This is a tricky question because 12 a.m. and 12 p.m. are ambiguous and should not be used.
To illustrate this, consider that “a.m.” and “p.m.” are abbreviations for “ante meridiem” and “post meridiem,” which mean “before noon” and “after noon,” respectively. Since noon is neither before noon nor after noon, a designation of either a.m. or p.m. is incorrect. Also, midnight is both twelve hours before noon and twelve hours after noon.
It is fair to say, however, that the shortest measurable duration after noon should be designated as p.m. For example, it would be applicable for a digital clock changing from 11:59:59 a.m. to 12:00:00 to indicate p.m. as soon as it the 12:00 appears, and not delay the display of the p.m. by a minute, or even a second. The same is true for midnight, but there is an added issue of which day midnight refers to (see below).
Hours of operation for a business or other references to a block of time should also follow this designation rule.
For example, a business might be open on Saturdays from 8 a.m. to noon or weekends from 3:30 p.m. until midnight.