Timestamp to date
Convert timestamp to human readable date. Supports seconds, milliseconds, and nanoseconds.
In 2038 a 32-bit clock does not reset to 1970 — it lands in 1901
A signed 32-bit timestamp runs out at 2,147,483,647 seconds, which is 03:14:07 UTC on 19 January 2038. The next second does not wrap to zero. It wraps to the most negative value the type can hold, putting the clock at 13 December 1901 — a system that fails this way jumps backwards by 137 years.
How it works
- Converts a Unix timestamp to a readable date and back, in UTC and local time.
- Detects whether the input is in seconds or milliseconds, which is the most common mistake.
- Handles negative timestamps, which are valid and represent dates before 1970.
timestamp = seconds elapsed since 1970-01-01 00:00:00 UTC 32-bit signed maximum = 2,147,483,647 → 2038-01-19 03:14:07 UTC the next second wraps to −2,147,483,648 → 1901-12-13 20:45:52 UTC 64-bit signed maximum ≈ 9.223 × 10¹⁸ seconds — roughly 292 billion years
Worked example
The same ten-digit value read two ways, plus the boundary that ends 32-bit time.
- 1770000000 read as seconds → 2026-02-02
- 1770000000 read as milliseconds → 1970-01-21
- 10 digits means seconds; 13 digits means milliseconds
- 2147483647 → 2038-01-19 03:14:07 UTC
- one second later → 1901-12-13 20:45:52 UTC
The unit error is the dangerous one because it fails quietly. Reading milliseconds as seconds lands you in the year 58,000 and is obvious on sight; reading seconds as milliseconds lands you in January 1970, which looks like a plausible date and passes review.
Reading the result
- A date of 1 January 1970 in production almost always means a null or zero reached the formatter rather than a real timestamp. The epoch is the default value of an uninitialised integer, which is why that date appears so often in bug reports.
- Negative timestamps are entirely valid and represent dates before 1970 — −86,400 is 31 December 1969. Systems that reject them cannot store historical dates, which is a real limitation rather than a safety measure.
- The timestamp itself carries no time zone; it is an absolute count of seconds. The zone enters only at formatting, which is why the same value renders as two different calendar dates for two users and why storing local time instead of a timestamp causes so much grief.
- Unix time ignores leap seconds by definition, repeating or stretching a second rather than counting it. It is therefore not a true count of elapsed SI seconds, which matters for precise interval measurement and almost never for anything else.
Common questions
- Why does my date show as 1970?
- Because the value reaching the formatter was zero or null, and zero is the epoch. It is rarely a formatting bug — the timestamp was never set, or was lost somewhere upstream, and 1 January 1970 is what an unset integer looks like once rendered.
- How do I tell seconds from milliseconds?
- Count the digits. Contemporary timestamps are 10 digits in seconds and 13 in milliseconds. Treating seconds as milliseconds is the error worth guarding against, because it produces a date in early 1970 that looks real rather than an obviously absurd one.