The abbreviations AM and PM trace directly to classical Latin astronomical terminology. AM represents ante meridiem, translating to "before noon" or "before midday." PM stands for post meridiem, meaning "after noon."
The operative Latin word is meridies, which combines medius (middle) and dies (day). In astronomy, this refers to the local meridian line: an imaginary great circle projected across the sky from true north to true south, passing directly overhead through the observer's zenith. When the sun crosses this celestial meridian at its highest daily elevation, an observer experiences true solar noon.
Any instant before the sun touches that overhead arc falls under the label ante meridiem. The second the sun slips past that invisible axis, the day enters post meridiem. The system is essentially an ancient solar tracking formula preserved in modern digital code.