A Unix timestamp is a count since 00:00:00 UTC on 1 January 1970. The bug that bites everyone is the unit: some systems count seconds, some milliseconds, and a few go to microseconds or nanoseconds.
Tell the unit from the number of digits
For any date between roughly 2001 and 2286:
| Digits | Unit | Example |
|---|---|---|
| 10 | seconds | 1767225600 |
| 13 | milliseconds | 1767225600000 |
| 16 | microseconds | 1767225600000000 |
| 19 | nanoseconds | 1767225600000000000 |
All four are 1 January 2026, 00:00 UTC.
Unix tools, PostgreSQL's extract(epoch ...), Python's time.time() and JWT exp claims use seconds. JavaScript's Date.now() and Java's System.currentTimeMillis() use milliseconds.
The classic JavaScript mistake
// exp from a JWT is in seconds
const exp = 1767225600;
new Date(exp); // 1970-01-21T10:53:45.600Z (wrong)
new Date(exp * 1000); // 2026-01-01T00:00:00.000Z (right)
If a date comes out in January 1970, you passed seconds where milliseconds were expected. If it comes out tens of thousands of years in the future, it's the other way round.
Going back the other way
Math.floor(Date.now() / 1000); // now, in seconds
Math.floor(new Date("2026-01-01T00:00:00Z") / 1000); // 1767225600
Always include a Z or an offset in the date string. Without one, date-time strings are read as the machine's local time, so the same code gives different timestamps on different servers.
Python
from datetime import datetime, timezone
datetime.fromtimestamp(1767225600, tz=timezone.utc)
# 2026-01-01 00:00:00+00:00
Pass tz; without it you get a naive local time.
Quick checklist
- Count the digits before converting.
- Store and send UTC; convert to a time zone only for display.
- Negative timestamps are valid and mean dates before 1970.
- Local clock times can be skipped or repeated when daylight saving changes, so "2:30 AM local" may not exist, or may exist twice.
Disclosure: I run GoToolsOnline. Its free Unix Timestamp Converter detects seconds, ms, µs or ns, shows the moment in UTC and any time zone, converts dates back to epoch time, and flags DST gaps. It runs in your browser.
Top comments (0)