Unix timestamps explained: seconds, milliseconds and time zones

Published

A Unix timestamp counts the seconds since 00:00:00 UTC on 1 January 1970, a moment known as the Unix epoch. 1700000000 is 22:13:20 UTC on 14 November 2023.

One number, every time zone

A timestamp identifies an instant, not a wall-clock time. At the moment 1700000000, it was 22:13 in London and 03:43 the next morning in New Delhi, but the timestamp was the same in both places. Time zones only matter when you turn a timestamp into a date for a person to read.

That is why storing timestamps (or UTC dates) and converting to local time at display time avoids most time zone bugs.

Seconds or milliseconds?

Different systems count in different units:

Unit Digits today Typical source
Seconds 10 Unix tools, PostgreSQL extract(epoch …), most APIs
Milliseconds 13 JavaScript Date.now(), Java, many JSON APIs
Microseconds 16 Python time.time_ns() // 1000, some databases
Nanoseconds 19 Go time.Now().UnixNano(), tracing systems

If a date comes out in January 1970, a seconds value was probably read as milliseconds. If it lands tens of thousands of years in the future, milliseconds were read as seconds.

Common mistakes

  • Parsing a date without a time zone. 2024-05-17T09:30:00 has no offset, so most languages assume local time. Add Z or an offset such as +05:30 when you mean a specific instant.
  • Adding 86,400 seconds to get “tomorrow”. On days when daylight saving time changes, a local day is 23 or 25 hours long. Use your language’s calendar functions for date arithmetic.
  • Storing timestamps in 32-bit integers. A signed 32-bit timestamp overflows at 03:14:07 UTC on 19 January 2038. Use 64-bit integers.

Convert one now

Paste any timestamp or date into the Timestamp Converter. It detects the unit from the number of digits and shows the date in any time zone.