- always store date and time in ISO 8601 format, UTC timezone (e.g.
2023-01-01T00:00:00Z) - when necessary to store the timezone, store it separately from the date and time
- always use libraries for date and time manipulation (e.g.
date-fns) ¹ - API endpoints should accept either ISO datestrings or timestamps ²
- JS uses milliseconds for timestamps, other languages (e.g. PHP) use seconds ³
- see ¹
- see ²
- see ³
toLocaleDateStringet al.: always explicitely pass formatting options to avoid unexpected results in some locales- only create dates from string when ISO
- it's useful to store user-provided date and time values in separate variables as numbers (e.g.
new Date(year, zeroIndexedMonth, day, hours, minutes, seconds))
- never take the order for granted (e.g.
11/10/1990could mean1990-10-11or1990-11-10)
- make sure
full-icuis enabled when running test suites or formatting might default toen-US