Unix Timestamps: Right Unit and Time Zone?
In this article
Unix timestamps count seconds since January 1, 1970 UTC, and they are always in UTC—so the correct unit is seconds and the correct time zone is UTC. When you read a timestamp, you must convert it to your local time zone for display, but the stored value itself never changes.
in t | Unix timestamp | s | 1700000000 | 0 in tz | Time zone offset from UTC | h | 0 | -12 out local | Local date and time | clock | t + tz * 3600 | 0 out utc | UTC date and time | clock | t | 0 out days | Days since epoch | days | t / 86400 | 2
Formula
The Unix timestamp is defined as the number of seconds that have elapsed since 00:00:00 Coordinated Universal Time (UTC) on Thursday, 1 January 1970, not counting leap seconds. The formula to convert a timestamp to a human-readable date is:
UTC time = epoch + timestamp seconds
Where:
- epoch = 1970-01-01 00:00:00 UTC
- timestamp = the integer number of seconds (can be negative for dates before 1970)
- UTC = the time standard used as the global reference
To get local time, add the time zone offset (in hours) to the UTC time:
Local time = UTC + offset
For example, if your time zone is UTC+2, add 2 hours to the UTC time. If you are in UTC-5, subtract 5 hours.
Worked Example
Using the default values from the calculator:
- Timestamp: 1,700,000,000 seconds
- Time zone offset: 0 (UTC)
Step 1: Convert the timestamp to a date. 1,700,000,000 seconds after 1970-01-01 00:00:00 UTC is 2023-11-14 22:13:20 UTC. (You can verify this by dividing by 86,400 seconds per day: 1,700,000,000 / 86,400 = 19,675.9259 days, which is about 53.9 years.)
Step 2: Add the time zone offset. With offset 0, the local time is the same as UTC: 2023-11-14 22:13:20.
Step 3: The calculator shows the local time as 22:13:20 (on a 24-hour clock) and the UTC time as the same. The days since epoch is 19,675.93 days.
Why Seconds and UTC?
The Unix epoch was chosen because 1970 was a convenient, round year for early Unix developers. The unit of seconds was selected because it is small enough to represent precise moments, yet large enough to cover a wide range of dates. UTC was chosen as the reference because it is a global standard unaffected by daylight saving time or regional offsets. This means a timestamp like 1700000000 refers to the exact same instant everywhere on Earth, regardless of where you are.
If you stored timestamps in local time, the same moment would be represented by different numbers in different places, causing chaos in distributed systems. By using UTC, every system can agree on the same number, and each user can convert it to their own local time for display.
Common Mistakes: Milliseconds vs. Seconds
One of the most frequent errors is confusing seconds with milliseconds. Many programming languages and APIs (like JavaScript’s Date.now()) return milliseconds since the epoch, not seconds. A millisecond timestamp is 1,000 times larger than a second timestamp. For example, 1700000000 seconds is 2023-11-14, but 1700000000 milliseconds is 1970-01-20 16:13:20 UTC. Always check the documentation to know which unit you are dealing with.
Another common mistake is ignoring the time zone when displaying. If you take a UTC timestamp and treat it as local time without conversion, you will be off by your time zone offset—potentially by hours. For instance, a timestamp that is 12:00 UTC will be 07:00 in New York (UTC-5) in winter, but 08:00 in summer (UTC-4).
Leap Seconds and Their Impact
Unix timestamps ignore leap seconds. A leap second is an occasional one-second adjustment added to UTC to keep it in sync with astronomical time. The Unix system simply does not count these extra seconds, so a timestamp can be off by a few seconds from actual UTC. For most applications, this is irrelevant, but for high-precision astronomy or some financial systems, it matters. The International Earth Rotation and Reference Systems Service (IERS) announces leap seconds, but they are not represented in Unix time.
How to Choose the Right Unit and Time Zone
When reading a Unix timestamp, you need to know two things: the unit (seconds or milliseconds) and the time zone you want to display it in. Here is a simple checklist:
- Identify the unit: check the source of the timestamp (API, database, etc.) to see if it is seconds or milliseconds.
- Convert to seconds if needed: if it is milliseconds, divide by 1000.
- Use a conversion tool or function that automatically handles the epoch and UTC.
- For display, apply the desired time zone offset (e.g., using the
Intl.DateTimeFormatin JavaScript ordatetime.fromtimestamp()in Python, which uses local time by default). - Never store timestamps in local time; always store UTC and convert on display.
If you are working with dates before 1970, the timestamp will be negative. For example, -86400 corresponds to 1969-12-31 00:00:00 UTC. Negative timestamps are perfectly valid and handled by most systems.
Limitations of Unix Timestamps
Unix timestamps have a finite range. On 32-bit systems, the maximum value is 2,147,483,647, which corresponds to 2038-01-19 03:14:07 UTC. This is known as the Year 2038 problem. After that, 32-bit signed integers overflow. Most modern systems use 64-bit integers, which can represent dates billions of years into the future, but legacy systems may still face this issue.
Another limitation is that Unix timestamps do not include time zone information. They are simply a number; the interpretation depends on the context. If you receive a timestamp without knowing its unit or that it is UTC, you cannot correctly convert it. Always document the unit and the fact that it is UTC.
Frequently Asked Questions
Is a Unix timestamp always in UTC?
Yes, by definition, Unix timestamps are always in UTC. The number represents seconds since 1970-01-01 00:00:00 UTC. There is no time zone embedded in the value; it is a universal reference.
How do I convert a Unix timestamp to my local time?
Take the timestamp (in seconds) and add the offset of your time zone from UTC. For example, if you are in UTC+5:30, add 5.5 hours (or 19,800 seconds). Many programming languages have built-in functions that do this automatically, like datetime.fromtimestamp() in Python, which uses the system’s local time zone.
Why do some timestamps have 13 digits?
Those are in milliseconds, not seconds. JavaScript’s Date.now() and many APIs return milliseconds. To get seconds, divide by 1000. For example, 1700000000000 milliseconds equals 1700000000 seconds.
What happens if I use the wrong time zone?
You will display the wrong local time. The timestamp itself is correct, but the conversion will be off by the difference between the actual time zone and the one you used. For example, if you treat a UTC timestamp as UTC-5 when it should be UTC+2, you will be 7 hours off.
Can a Unix timestamp be negative?
Yes, negative timestamps represent dates before 1970. For example, -3600 is 1969-12-31 23:00:00 UTC. Not all systems handle negative timestamps gracefully, but most modern ones do.
Will Unix timestamps ever run out?
On 32-bit systems, they will overflow on January 19, 2038. On 64-bit systems, the maximum value is about 9.2 quintillion seconds, which is far beyond the age of the universe, so it will not run out for practical purposes.