If you have ever seen a number like 1763151600 in a log file, a web address or a database, you have seen Unix time. It is the simplest way a computer can store a moment, as a single number. This guide explains how it works, how to read it, and what happens in the year 2038.
- Unix time is the number of seconds since midnight UTC on January 1, 1970.
- A timestamp is always in UTC, and local time is added when it is displayed.
- Older 32-bit systems run out of numbers on January 19, 2038.
The basic idea
Unix time, also called epoch time or a Unix timestamp, is the number of seconds that have passed since midnight UTC on January 1, 1970. That moment is called the Unix epoch. A time before the epoch is a negative number. Because it is a single number and does not depend on a time zone, it is easy to store, compare and calculate with. To find the time between two events, you subtract one timestamp from the other and get the answer in seconds.
The choice of 1970 is mostly practical. The first versions of the Unix operating system were created around 1969 and 1970 at Bell Labs, and the designers needed a recent starting point that would fit in the memory of the machines at the time.
Some milestones
It can help to know a few landmarks:
- 0 is 1970-01-01 00:00:00 UTC.
- 1,000,000,000 was reached on 2001-09-09 at 01:46:40 UTC.
- 1,700,000,000 was reached on 2023-11-14 at 22:13:20 UTC.
- 2,000,000,000 will be reached on 2033-05-18 at 03:33:20 UTC.
- 2,147,483,647 is 2038-01-19 at 03:14:07 UTC, the largest value a signed 32-bit number can hold.
One day is 86,400 seconds, so you can estimate a date by dividing a timestamp by 86,400 to get the number of days since the epoch.
Converting by hand
Take the timestamp 1,700,000,000. Divide by 86,400 to get the number of whole days: 19,675 days, with 80,000 seconds left over. The remainder divided by 3,600 gives 22 hours, and the rest is 13 minutes and 20 seconds. So the time of day is 22:13:20. Then you count 19,675 days from January 1, 1970. 53 years take you to January 1, 2023, with 13 leap days in between, which is 19,358 days, and 317 days remain, which is November 14. You arrive at 2023-11-14 22:13:20 UTC. The date tool and the Unix timestamp tool on this site do it instantly.
Seconds or milliseconds?
A common source of mistakes is that some systems count in milliseconds. JavaScript, for example, uses milliseconds, so Date.now() returns a number with 13 digits, while a timestamp in seconds currently has 10 digits. If you convert a 13-digit number as if it were in seconds, you get a date thousands of years in the future. If you convert a 10-digit number as if it were in milliseconds, you get a date in January 1970.
Time zones and leap seconds
A Unix timestamp is always in UTC. The local time is something you add when you show the time to a person. This is why developers store timestamps in UTC and convert only when they display them, using a library that knows the time zone rules. Unix time also ignores leap seconds. Each day is treated as exactly 86,400 seconds, so on a day with a leap second, the clock repeats a second or slows down for a while, as described in the guide on UTC and atomic time.
The year 2038 problem
On many older systems, Unix time is stored as a signed 32-bit integer. The largest number it can hold is 2,147,483,647, which is reached at 03:14:07 UTC on January 19, 2038. One second later the number wraps around to a large negative value, and the system would believe it is December 1901. This is called the year 2038 problem. Modern systems use 64-bit numbers, which will last for about 292 billion years, so most software is safe, but embedded devices, older databases and file formats can still be affected.
Where you meet Unix time
Timestamps are used in log files, databases, web APIs, file systems, tokens used for logins and caches. In a web address or a downloaded file you may see a long number that is the time of creation. Programming languages have simple functions for them: in JavaScript, new Date(1700000000 * 1000) gives a date, and in Python, datetime.fromtimestamp(1700000000, timezone.utc) does the same. A timestamp is also the simplest way of sharing a moment between people in different time zones, since everyone converts it to their own local time.