How programmers think about dates and times
Some date and time formats are better than others.

There are a few sensible ways to think about representing time in a computer (or outside of one).
Representing the date
YYYY-MM-DD is the best way to represent a date. It starts with the coarsest measurement (the year). As you read from right to left, you get more specific information.
From a YYYY-MM-DD date, you can convert with ease to any other, inferior date representation.
Representing the time
Most people write the time the same way: HH:MM:SS. This makes sense because you can include it after a date. If you wrote the date right (YYYY-MM-DD) then the “coarsest-to-finest” pattern continues. Year, month, day, hour, minute second. This assumes that you wrote your date in the correct way - YYYY-MM-DD.
If you need sub-second precision, you can continue to add digits to the decimal part of the seconds. Milliseconds, microseconds, nanoseconds - whatever you want.
12 vs 24 hour time
24 hour time is the only reasonable way to reckon time during the day. When you express time using the 24 hour clock, there is no ambiguity. The 12 hour clock shows the same time twice a day, leading to potential confusion. There is never a reason to use 12 hour time in any time stamp that computers will read.
In human situations, AM or PM is usually clear from context, but 24 hour time is still better. 24 hour time always has greater clarity and less ambiguity. This is why military, railroad, and aviation conventions use it.
From a simple “YYYY-MM-DD HH:MM:SS” timestamp, you can convert to any other representation of date and time. That makes it the most universal starting point to represent dates and times.

Photo by Nathan Dumlao on Unsplash
Originally published on Substack.