How to Convert Unix Timestamps
A Unix timestamp is the number of seconds since midnight UTC on 1 January 1970 — the "epoch". It shows up in logs, databases, JWTs, and APIs because it's a single unambiguous number. Here's how to work with it.
Seconds or milliseconds?
Two conventions are common, and telling them apart is the usual gotcha:
- Seconds — a 10-digit number today, e.g.
1717000000(used by Unix, Postgres, JWTexp). - Milliseconds — a 13-digit number, e.g.
1717000000000(used by JavaScript'sDate.now()).
A quick rule: 13 or more digits is milliseconds; 10 is seconds. Multiply seconds by 1000 to get milliseconds.
UTC vs local time
The timestamp itself is always UTC — it has no time zone. The display is where zones come in. 2024-05-29T16:26:40Z (the Z means UTC) is the same instant everywhere; your local clock just shows it shifted by your offset. When you convert, always check whether you're reading the UTC or the local row.
Converting back
Going from a date to a timestamp is just the reverse: parse the date into an instant, then read its epoch seconds or milliseconds. A date with no time zone is interpreted in your local zone, so 2024-05-29 12:00 means noon where you are.
Related
Part of The Complete Guide to Dates and Times; see also What Is Unix Time?. For scheduling, the Cron Expression Parser; and the JWT Decoder, whose iat and exp claims are Unix timestamps.
Try it
Paste a timestamp or a date and see every format at once, with a live clock — everything runs in your browser, nothing uploaded.