How Unix time works
Almost every computer keeps time as one number: the seconds since midnight UTC on 1 January 1970. That number, Unix time, is how files, databases, logs and APIs store a moment without caring about time zones. Here is where the epoch comes from, how the different units work, why Unix time pretends leap seconds do not exist, and why 32-bit clocks run out in January 2038.
The Unix epoch
Unix time is the number of seconds that have passed since the epoch, 1970-01-01T00:00:00Z. The first Unix systems at Bell Labs counted sixtieths of a second from 1971; when the count was changed to whole seconds, its start was moved to the round date of 1 January 1970. Because it is measured in UTC, a timestamp names the same instant everywhere: 1,700,000,000 was 22:13:20 in London, 23:13:20 in Paris and 17:13:20 in New York. Moments before 1970 are negative numbers.
Seconds, milliseconds, microseconds and nanoseconds
The classic Unix timestamp counts seconds, as C's time() and most command-line tools still do. JavaScript's Date.now() and Java's System.currentTimeMillis() count milliseconds, PostgreSQL and Python work to microseconds, and Go's UnixNano() and the Linux clock_gettime() to nanoseconds. The same moment is therefore 10, 13, 16 or 19 digits long today. A double-precision number holds whole numbers exactly only up to 2⁵³, about 9 × 10¹⁵, so nanosecond timestamps, around 1.7 × 10¹⁸, need 64-bit integers or BigInt to keep their last digits.
Why leap seconds are left out
The Earth's rotation is slightly irregular, so since 1972 timekeepers have inserted 27 leap seconds, the last at the end of 2016, to keep UTC within 0.9 seconds of the Sun. Unix time ignores them: by definition every day has exactly 86,400 seconds. During a leap second, 23:59:60, a Unix clock repeats a second, or the extra second is smeared over many hours. So 23:59:60 has no timestamp of its own, and the difference between two timestamps leaves out the leap seconds between them. In 2022 the world's metrology body decided to stop adding leap seconds by 2035.
Time zones, ISO 8601 and RFC 2822
A timestamp has no time zone; a zone is only needed to write it as a date. Zone rules change by law, so software uses the IANA time zone database, with names such as Europe/Paris and America/New_York that record every change of offset and daylight saving time. To exchange dates as text, ISO 8601 and its internet profile RFC 3339 write 2023-11-14T22:13:20Z or 2023-11-14T17:13:20-05:00, largest unit first so they sort as text, while the older RFC 2822 of e-mail and HTTP writes Tue, 14 Nov 2023 17:13:20 -0500.
The year 2038 problem
Many systems store Unix time in a signed 32-bit integer, whose largest value is 2,147,483,647. That second is 19 January 2038 at 03:14:07 UTC; one second later the counter overflows to −2,147,483,648, which reads as 13 December 1901 at 20:45:52. Embedded devices, old file formats and database columns with 32-bit time are at risk, much like the year 2000 problem. A 64-bit count fixes it for 292 billion years: Linux uses 64-bit time on 32-bit systems since version 5.6 (2020), and databases are moving from 32-bit TIMESTAMP columns to 64-bit types.
Frequently asked questions
What is epoch time?
Another name for Unix time: the number of seconds since the Unix epoch, 1 January 1970 at 00:00:00 UTC. It is also called POSIX time or a Unix timestamp. Other systems use other epochs: Windows file times count 100-nanosecond steps from 1601, and Apple's Core Data counts seconds from 2001.
Is Unix time the same everywhere?
Yes. A Unix timestamp is the same number at the same moment in every time zone, because it counts from a fixed instant in UTC. Only when it is written as a date does the zone matter: 0 is 1 January 1970 at 00:00 in London but 31 December 1969 at 19:00 in New York.
What happens to Unix time during a leap second?
Nothing is added. A day in Unix time always has 86,400 seconds, so the leap second 23:59:60 gets no number of its own. Most systems let the clock repeat a second; others smear the extra second over the hours around it. Either way, Unix time is back in step with UTC after the leap second.
Will 64-bit timestamps run out?
Not in any practical sense. A signed 64-bit count of seconds lasts about 292 billion years, some 20 times the age of the universe. A signed 64-bit count of nanoseconds, as in Go and many databases, reaches April 2262.
Ready to try it?
Open PictorX in your browser — no install, no credit card required to start.
Open the Unix Timestamp Converter