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.
When someone refers to "midnight tonight" or "midnight last night" the reference of time is obvious. However, if a date/time is referred to as "at midnight on Friday, October 20th" the intention could be either midnight the beginning of the day or midnight at the end of the day.
To avoid ambiguity, specification of an event as occurring on a particular day at 11:59 p.m. or 12:01 a.m. is a good idea, especially legal documents such as contracts and insurance policies. Another option would be to use 24-hour clock, using the designation of 0000 to refer to midnight at the beginning of a given day (or date) and 2400 to designate the end of a given day (or date).
Sunrise/sunset tables can be dynamically generated at these links:
Dawn is the time of morning when the Sun is 6° below the horizon. Respectively, dusk occurs when the Sun is 6° below the horizon in the evening. Sunrise is the time when the first part of the Sun becomes visible in the morning at a given location. Sunset is the time when the last part of the Sun disappears below the horizon in the evening at a given location. Twilight refers to the period between the dawn and sunrise and between sunset and dusk.
The definitions are from the National Weather Service and more detail can be found in their glossary.