Q. Is midnight the end of one day or the beginning of the next? When it’s exactly 12:00, is that the first second of a new day or that the last second of the previous day?
The exact moment of midnight is technically neither yesterday or today.
It completely depends on how you use it in relation to other time. You can say “tonight at midnight” to suggest it is the ending of the day, or “beginning at midnight” to suggest it is the beginning of the new day, and both are correct. By definition it is the dividing line between the days and does not belong to either exclusively (though it can’t belong to both at the same time, if you follow).
That said, in common usage, midnight is usually referred to as the first moment of the new day. For example, on New Year’s Eve, it is generally accepted that the stroke of midnight is the beginning of the new year, meaning it is the beginning of the first day of the year. In the same way, midnight is often written as 12AM, suggesting it is the beginning of the new day. (12PM is generally used to mean mid-day, or noon.)