Abbreviated from Latin. A.M. means Ante Meridiem and P.M. means Post Meridiem.
Meridiem = Meridian, the dividing line between the early day and the late day, otherwise known as noon.
It is better not to speak of 12 a.m. or 12 p.m., but rather 12 noon or 12 midnight, or simply, noon or midnight. For 24 hour systems, this would be 12:00 for noon and 00:00 for midnight.