Timezones.in — Stay In Sync

Unix timestamp: what it is and how to convert it

Developer · Published 20 November 2026 · Facts computed live from the IANA time zone database

Short answer

A Unix timestamp is the number of seconds that have passed since 00:00:00 UTC on 1 January 1970, the Unix epoch, not counting leap seconds. It has no time zone: the same moment gives the same number in Tokyo, London and New York. Time zones only matter when you turn the number into a date and time for people to read.

That makes it one of the simplest ways for computers to agree on a moment. A database in Mumbai and a server in Virginia can swap the number 1700000000 and both know exactly which second is meant: 22:13:20 UTC on 14 November 2023.

How a Unix timestamp works

The count started at zero at midnight UTC on 1 January 1970, a date picked by the early Unix developers as a convenient round starting point. Every second since then adds one. Moments before 1970 are negative numbers, so -86400 is midnight UTC on 31 December 1969.

The number is the same everywhere on Earth at the same instant. There is no "Unix time in India" or "Unix time in New York". If you see a timestamp that seems to be "in" a time zone, someone has added or subtracted an offset by mistake, and that is a bug.

Three things are worth knowing from the start:

  • It counts seconds, not calendar days. Each day is treated as exactly 86,400 seconds.
  • Leap seconds are not counted. When a leap second was added to UTC, Unix time either repeated a second or, on some systems, spread the extra second across the surrounding hours. That keeps the arithmetic simple at the cost of being off by one second for a moment.
  • It is UTC underneath. When you convert a timestamp to a readable date, you choose the time zone at that point. Converting to UTC gives the same result on every machine; converting to "local time" depends on the computer's settings.

Seconds or milliseconds?

The most common mistake is mixing up the two units. Most systems (Unix shells, Python, PHP, most databases and APIs) use seconds. JavaScript and Java use milliseconds.

You can usually tell them apart by length. A timestamp in seconds for any date between 2001 and 2286 has 10 digits. The same moment in milliseconds has 13 digits. If you pass milliseconds to a function that expects seconds, you get a date tens of thousands of years in the future. If you pass seconds to JavaScript's new Date(), you get a date in January 1970. Either result is a strong hint that the units are wrong.

Language or tool Current timestamp Timestamp to a date
JavaScript Math.floor(Date.now() / 1000) new Date(ts * 1000).toISOString()
Python int(time.time()) datetime.fromtimestamp(ts, tz=timezone.utc)
Shell (Linux) date +%s date -u -d @1700000000
Shell (macOS) date +%s date -u -r 1700000000
PostgreSQL extract(epoch from now()) to_timestamp(1700000000)

Converting in code

In JavaScript, Date.now() returns milliseconds, so divide by 1,000 and round down to get seconds:

const seconds = Math.floor(Date.now() / 1000);
new Date(1700000000 * 1000).toISOString(); // "2023-11-14T22:13:20.000Z"

In Python, time.time() returns seconds as a decimal. To turn a timestamp into a date, always pass a time zone. Without one, Python gives you a "naive" datetime in the computer's local time, which is a frequent source of hour-shifted bugs:

import time
from datetime import datetime, timezone

now = int(time.time())
datetime.fromtimestamp(1700000000, tz=timezone.utc).isoformat()
# '2023-11-14T22:13:20+00:00'

On the command line, date +%s prints the current timestamp. To go the other way, GNU date on Linux uses -d @, while macOS and BSD use -r. The -u flag prints the result in UTC instead of the machine's local zone.

The Z at the end

When you turn a timestamp into text, the usual format is ISO 8601, for example 2023-11-14T22:13:20Z. The final "Z" means the time is in UTC, an offset of zero, the same as UTC+0. It is the same Z that pilots read as Zulu time. You may also see +00:00, which means the same thing. A string with no Z and no offset is ambiguous: the reader cannot tell which zone it was written in.

A good rule for software is to store and send timestamps or UTC strings with a Z, and convert to local time only on the screen, using the reader's own zone. Our page on what time zone you are in shows what your browser reports, which is what most front-end code will use.

The Year 2038 problem

Many older systems stored Unix time in a signed 32-bit integer. The largest value that fits is 2,147,483,647, which is reached at 03:14:07 UTC on 19 January 2038. One second later, the number overflows and wraps round to a large negative value, which those systems read as a date in December 1901.

Modern operating systems, languages and databases use 64-bit values, which push the limit billions of years away. The risk sits in older embedded devices, file formats and database columns that still use 32 bits. If you design a schema today, use a 64-bit integer or a proper timestamp type.

When you should not use Unix time

A timestamp records an instant. It is the right choice for logs, events, expiry times and anything that happened at one moment. It is not enough for a future event tied to a place, such as "09:00 every Monday in New York". If New York's daylight saving rules change, a timestamp calculated today would be an hour out. For those, store the local time and the IANA zone name (America/New_York) and work out the instant when you need it.

For converting between named zones, our time zone converter and pages such as EST to UTC do the arithmetic, including daylight saving. If you need the current time or offsets in your own code, our free time API returns them as JSON.

Frequently asked questions

Is a Unix timestamp in UTC?

It is based on UTC and has no time zone of its own. The same instant has the same timestamp everywhere. Time zones only come in when you display it.

How do I know if a timestamp is in seconds or milliseconds?

Count the digits. Current timestamps in seconds have 10 digits; in milliseconds they have 13. JavaScript and Java use milliseconds; most other tools use seconds.

Can a Unix timestamp be negative?

Yes. Negative numbers count backwards from 1970, so they describe earlier dates. Not every system accepts them, so test before relying on it.

What happens on 19 January 2038?

Systems that store Unix time in a signed 32-bit integer run out of room at 03:14:07 UTC and wrap to a date in 1901. Systems using 64-bit time are not affected.

Does Unix time include leap seconds?

No. Every day counts as 86,400 seconds, so Unix time does not show the leap seconds that were added to UTC.

Sources