According to traditional Catholic rules (before Vatican the 2nd Council), as well as in Eastern Orthodox traditions, those who want to receive the Sacraments should fast, i.e. do not consume any food or liquids, from midnight until receiving Holy Communion.
Presumably, this rule is based on the Canon XLI of the Council of Carthage (419):
That by men who are fasting sacrifices are to be offered to God. THAT the Sacraments of the Altar are not to be celebrated except by those who are fasting, except on the one anniversary of the celebration of the Lord’s Supper; for if the commemoration of some of the dead, whether bishops or others, is to be made in the afternoon, let it be only with prayers, if those who officiate have already breakfasted.
At least, it is how this tradition is explained in the Eastern Orthodox Church.
But I don't see in this canon any mentioning of midnight. Why fasting is obliged to be from midnight?