Unix timestamps and time zones

Published 17 October 2026

A Unix timestamp is a count of seconds since 1970-01-01T00:00:00Z. It names an instant, and an instant has no time zone. A time zone only decides how that instant is printed. Almost every timestamp bug comes from confusing the two.

Seconds or milliseconds

The classic value is in seconds and has about 10 digits. JavaScript's Date.now() returns milliseconds, about 13 digits. Mixing them shifts the result by a factor of a thousand:

1719900000      seconds     2024-07-02 06:00:00 UTC
1719900000000   milliseconds 2024-07-02 06:00:00 UTC

A milliseconds value read as seconds lands in the year 56434; a seconds value read as milliseconds lands in January 1970. Both look plausible enough to survive a code review.

The same instant in three places

1719900000  =  2024-07-02 06:00:00 UTC
            =  2024-07-02 08:00:00 UTC+2   (Berlin, summer)
            =  2024-07-02 15:00:00 UTC+9   (Tokyo)

All three lines describe the same moment. If an example gives a wall-clock time without a zone or an offset, it cannot be reproduced.

The five mistakes

  1. Storing local time. A database column filled with the server's local clock breaks the moment the server moves region or the offset changes.
  2. Formatting on the server. Rendering dates with the server's zone shows users a time that is correct only for the server.
  3. Assuming daylight saving is a fixed offset. During a transition a wall-clock time can occur twice or not at all, so "2024-11-03 01:30" is ambiguous in New York.
  4. Treating 2038 as distant. A signed 32-bit time_t overflows on 2038-01-19T03:14:07Z. Embedded systems and older database schemas still hit this.
  5. Comparing values from different sources. An API returning seconds and a browser returning milliseconds will disagree by a thousand times, and the comparison will not raise an error.

Rules that avoid most of it

  1. Store UTC, always.
  2. Put the unit in the name: created_at_ms, not created_at.
  3. Convert to a zone only at the edge, when displaying.
  4. Use IANA zone names (Europe/Berlin), not fixed offsets.
  5. Test around the spring and autumn transitions, not just in midsummer.

When an ISO 8601 string is better

A timestamp is compact but opaque, and it has no room for a zone. For interchange, an ISO 8601 / RFC 3339 string such as 2024-07-02T06:00:00Z is self-describing and keeps the offset. Store a timestamp when you need arithmetic or compactness; store a string when you need to hand the value to a human or another system.

Convert between the two with Epoch Time, and read schedules with the cron parser — noting that a cron expression runs in the zone of the machine that executes it, which is often not yours.