There are no standards established for the meaning of 12am and 12pm. It is often said that 12am Monday is midnight on Monday morning and 12pm is midday. This puts all the times beginning with 12 and ending with am in the same one-hour block, similarly with those ending with pm.
It can also be argued that by the time you have seen a clock showing 12:00 at midday it is already post meridiem, and similarly at midnight it is already ante meridiem. Times in the first hour of the day are sometimes given as, for example, 00:47 am, with 00:00 am corresponding to midnight, but with a time twelve hours later given as 12:47 pm.