Unix timestamp vs ISO 8601: how to choose
Store and compute with Unix timestamps (an integer, no timezone ambiguity); transmit and log with ISO 8601 (human-readable, timezone included). The safest pattern: store a timestamp or a timezone-aware timestamptz in the database, and emit ISO 8601 UTC with a Z suffix from your API.
Key differences
| Aspect | Unix timestamp | ISO 8601 |
|---|---|---|
| Example | 1769500000 | 2026-01-27T08:26:40Z |
| Nature | Seconds since 1970-01-01 UTC | String with an explicit timezone |
| Timezone info | None — implicitly UTC | Explicit (Z or +08:00) |
| Readability | Poor — humans cannot read a date from it | Good — readable at a glance |
| Storage cost | 4-8 byte integer | 20-30 byte string |
| Compare and compute | Direct integer comparison, fastest | Needs parsing; lexicographic order works within one format |
| Year 2038 problem | 32-bit integers overflow | Not affected |
Unix timestamp
A single integer counting seconds since 1970-01-01 00:00:00 UTC (the millisecond version has 13 digits). It carries no timezone because it is inherently UTC, comparison is plain integer comparison so sorting and range queries are extremely fast, and it stores cheaply. The downsides: nobody can read a date out of it, and 32-bit integers overflow in January 2038 — always use 64-bit in new systems.
ISO 8601
A string shaped like 2026-01-27T08:26:40Z. The format is fixed and carries its own timezone (Z for UTC, or an explicit +08:00 offset), it is readable by humans, and within a single format lexicographic order equals chronological order so a string sort is a time sort. It is the de facto standard for JSON APIs, log files and HTTP headers. The costs are size and needing to parse before comparing.
How to choose
- Database storage, fast range queries → Unix timestamp or timestamptz
- API responses, logs, config files → ISO 8601 with Z or an explicit offset
- Front-end display → Take ISO 8601 and format it in the user local timezone
Related tools
FAQ
How do I tell seconds from milliseconds
Ten digits means seconds, thirteen means milliseconds. Mixing them makes times differ by a factor of 1000 — one of the most common integration bugs around.
What does the Z mean
Z is UTC zero offset (Zulu time). 2026-01-27T08:26:40Z is that instant in UTC, which is 16:26:40 Beijing time.
Will the 2038 problem actually happen
Yes, but only for legacy systems that store timestamps as 32-bit signed integers. Use a 64-bit integer or a database timestamptz column and it never touches you.