ISO 8601 or epoch time?

2023-11-14T22:13:20Z and 1700000000 are the same instant. One is easy for people and can carry an offset; the other is easy for arithmetic and cannot be misread.

The two formats

ISO 8601 / RFC 3339Unix epoch
Example2023-11-14T22:13:20Z1700000000
Readable by peopleyesno
Carries a UTC offsetyes: 2023-11-14T17:13:20-05:00no, always UTC
Precisionany, by adding decimals: …20.123Zdepends on an unstated unit
Sortingas text, only if every value uses the same offset and precisionas numbers, always
Arithmeticparse firstsubtract
Size20 to 35 characters10 to 19 digits, or 4 to 8 bytes in binary
Can express a date without a time, or a local timeyes: 2023-11-14, 2023-11-14T09:00no

RFC 3339 is the strict internet profile of ISO 8601 and what most APIs mean by "ISO date": a full date and time, T between them, and a mandatory Z or numeric offset.

Where each one goes wrong

ISO 8601 fails when the offset is left off. 2023-11-14T22:13:20 does not identify an instant, and each parser fills the gap differently: JavaScript assumes local time for that string but UTC for the date-only 2023-11-14. The standard also allows forms that many parsers do not accept, such as week dates (2023-W46-2), ordinal dates (2023-318) and the compact 20231114T221320Z.

Epoch time fails on the unit. Nothing in 1700000000000 says milliseconds, and a client that assumes seconds gets a date tens of thousands of years away. It also loses information: once a time is reduced to a number, you can no longer tell that the user entered it as 9 am in Sydney.

Choosing

  • Public JSON APIs: RFC 3339 strings in UTC, 2023-11-14T22:13:20Z. They explain themselves in a log or a debugger and cannot be off by a factor of 1000.
  • Tokens and protocols that fix the format: follow the specification. JWT exp, iat and nbf are epoch seconds; HTTP headers use the older format Tue, 14 Nov 2023 22:13:20 GMT.
  • High-volume events, metrics and binary formats: epoch integers, with the unit in the field name: timestamp_ms.
  • Databases: the native timestamp type, which stores an instant compactly and prints it as a date.
  • Future events at a local time, such as a meeting at 9 am in Sydney next year: store the local date-time and the zone name, Australia/Sydney. Neither an offset nor a timestamp survives a change to the daylight-saving rules.

Converting between them

JavaScript   new Date(1700000000 * 1000).toISOString()        →  2023-11-14T22:13:20.000Z
             Date.parse('2023-11-14T22:13:20Z') / 1000        →  1700000000
Python       datetime.fromtimestamp(1700000000, tz=timezone.utc).isoformat()
             datetime.fromisoformat('2023-11-14T22:13:20+00:00').timestamp()
GNU date     date -u -d @1700000000 +%Y-%m-%dT%H:%M:%SZ
             date -d 2023-11-14T22:13:20Z +%s

The timestamp converter does both directions and accepts offsets. Each language page has the tested equivalents.

Questions

What does the Z at the end of an ISO 8601 time mean?

Zero offset from UTC, sometimes read as "Zulu". 2023-11-14T22:13:20Z and 2023-11-14T22:13:20+00:00 are the same instant.

Is an ISO 8601 string or a timestamp better for a REST API?

An RFC 3339 string in UTC is the safer default: it is readable and carries no hidden unit. Use epoch numbers when a specification requires them or when size and speed matter.

Do ISO 8601 strings sort correctly as text?

Only if they all use the same offset (ideally Z) and the same number of decimal places. Mixed offsets sort by local clock reading, not by instant.