How it works
The input is converted to an ECMAScript Date, then tokens are replaced from the UTC calendar and clock fields in one pass. Numeric input is interpreted as seconds for values below the year-2100 threshold and milliseconds otherwise; Z and ZZ are emitted as UTC because no source time-zone identifier is retained.
- Token replacement is longest-first so YYYY is not partially consumed as YY plus literal text.
- The default pattern is sortable and unambiguous for logs: four-digit year, zero-padded month/day, and a 24-hour clock.
Worked example
Format ISO Date
Format a date using a custom pattern with day name
Input
2025-07-04T15:30:00Z
Output
2025-07-04 15:30:00
When to use this
Log lines, API fixtures, filenames, and database export columns use tokenized date strings.
Edge cases
- A numeric value below 4102444800 is treated as Unix seconds; a larger value is treated as milliseconds, so an early millisecond timestamp can be misclassified.
- A date-only string is parsed by the browser date implementation and then displayed at UTC midnight, not at the viewer's local midnight.
- Z and ZZ always show +00:00 or +0000 because the formatter normalizes to UTC and does not preserve an input offset.