Unix Timestamps Explained: Epoch Time, Milliseconds and Time Zones
- What a Unix timestamp is
- Why systems use timestamps instead of dates
- Seconds vs milliseconds: the most common bug
- Time zones: one instant, many displays
- The same timestamp around the world
- Daylight saving time
- The Year 2038 problem, briefly
- Frequently asked questions
- How do I get the current Unix timestamp?
- Why does my timestamp convert to a date in 1970?
- Is a Unix timestamp the same as UTC?
On this page
- What a Unix timestamp is
- Why systems use timestamps instead of dates
- Seconds vs milliseconds: the most common bug
- Time zones: one instant, many displays
- The same timestamp around the world
- Daylight saving time
- The Year 2038 problem, briefly
- Frequently asked questions
- How do I get the current Unix timestamp?
- Why does my timestamp convert to a date in 1970?
- Is a Unix timestamp the same as UTC?
Open almost any database, log file or API response and you'll find numbers like 1800000000 sitting where you'd expect a date. That's a Unix timestamp — and it's how most software actually thinks about time internally. Human-readable dates like "15 January 2027, 1:30 PM" are mostly produced at the very last moment, for display.
Timestamps are simple once you know what they count, but they're behind a surprising number of bugs: dates showing up in 1970, events appearing thousands of years in the future, and times that are off by exactly five and a half hours. Almost all of them come from three misunderstandings, which this guide covers in turn.
What a Unix timestamp is
A Unix timestamp is the number of seconds that have elapsed since 00:00:00 UTC on 1 January 1970, a moment known as the Unix epoch. The timestamp 0 is the epoch itself. The timestamp 1800000000 is 1.8 billion seconds later: 08:00:00 UTC on 15 January 2027. Moments before 1970 are represented by negative numbers.
There's one technical footnote worth knowing: Unix time ignores leap seconds. It treats every day as exactly 86,400 seconds, so it isn't a perfect count of elapsed physical seconds. For almost all application code this is invisible and irrelevant, but it's why scientific and financial systems sometimes use more specialised time scales.
Why systems use timestamps instead of dates
A date string like "03/04/2027 10:00" is surprisingly ambiguous. Is that 3 April or 4 March? 10:00 where? Was daylight saving in effect? A timestamp has none of these problems.
- Time zone independent: a timestamp identifies one exact instant, the same everywhere on Earth.
- Easy to compare and sort: a larger number is always later, so sorting events is a numeric sort.
- Easy arithmetic: one hour later is + 3600; one day later is + 86400; the time between two events is a subtraction.
- Compact and unambiguous: a single integer, with no locale-dependent format to parse.
The usual pattern is to store and transmit timestamps (or UTC-based ISO 8601 strings like 2027-01-15T08:00:00Z, which carry the same information), and convert to a local, human-readable format only when showing a date to a person.
Seconds vs milliseconds: the most common bug
Traditional Unix timestamps count seconds. JavaScript doesn't. Date.now() returns milliseconds since the epoch, new Date(value) expects milliseconds, and so do most JavaScript libraries. Java's System.currentTimeMillis() also uses milliseconds, while Python's time.time(), PHP's time(), Go's time.Now().Unix() and most databases work in seconds.
Mix the two up and you don't get an error — you get a perfectly valid, wildly wrong date. Here's what happens with the timestamp 1800000000:
- Interpreted correctly as seconds: 15 January 2027, 08:00:00 UTC.
- Seconds passed where milliseconds are expected (new Date(1800000000) in JavaScript): 21 January 1970 — about three weeks after the epoch, because the value is 1,000 times too small.
- Milliseconds (1800000000000) treated as seconds: a date around the year 59,000, because the value is 1,000 times too large.
- The fix in JavaScript: multiply seconds by 1,000 before creating a Date, and use Math.floor(Date.now() / 1000) when an API expects seconds.
Tip
Count the digits. A present-day timestamp in seconds has 10 digits (and will until the year 2286); in milliseconds it has 13. If you see a date in January 1970 or tens of thousands of years from now, the unit is almost certainly wrong by a factor of 1,000.
Time zones: one instant, many displays
A Unix timestamp has no time zone, because it's defined relative to UTC. There's only one 1800000000, and it refers to the same instant for everyone. What changes between locations is how that instant is displayed.
The same timestamp around the world
- UTC and London (GMT in January): 15 January 2027, 08:00.
- India (IST, UTC+5:30): 15 January 2027, 13:30.
- New York (EST, UTC−5 in January): 15 January 2027, 03:00.
- The underlying number, 1800000000, is identical in all three places.
This is why "converting a timestamp to a time zone" never changes the timestamp itself. You're only choosing which clock to read the instant from. The same logic explains the classic "off by 5:30" bug: a server in UTC and a browser in India are both showing the correct instant, just on different clocks, and the bug is that one of them is labelled as if it were the other.
Daylight saving time
Daylight saving is where the display side gets genuinely tricky. The offset for a place like New York changes twice a year, so converting a timestamp to local time has to use the rules that applied on that date, not today's offset. Use a proper time zone name such as America/New_York rather than a fixed offset like −05:00, and let your language's date library handle the rules.
Watch out
Store times in UTC (as timestamps or UTC ISO strings) and convert to local time only at display. Storing local times without an offset makes it impossible to reliably reconstruct the instant later — especially for times that fall inside a daylight saving changeover.
The Year 2038 problem, briefly
Many older systems stored timestamps as a 32-bit signed integer, which can hold a maximum value of 2,147,483,647. That second arrives at 03:14:07 UTC on 19 January 2038. One second later, a 32-bit counter overflows and wraps around to a large negative number — which those systems interpret as a date in December 1901.
For most modern software this is already solved: 64-bit operating systems, current databases and modern languages use 64-bit timestamps, which won't overflow for billions of years. The remaining risk sits in legacy code, old file formats, database columns defined as 32-bit integers, and long-lived embedded devices that can't easily be updated.
Frequently asked questions
How do I get the current Unix timestamp?
In JavaScript, Math.floor(Date.now() / 1000) gives seconds; Date.now() on its own gives milliseconds. In Python, int(time.time()). On macOS or Linux, date +%s in a terminal. A timestamp converter will also show the current value live.
Why does my timestamp convert to a date in 1970?
Almost always because a value in seconds was passed to something expecting milliseconds, such as JavaScript's Date constructor. Multiply it by 1,000 first. A timestamp of 0, or a null value coerced to 0, will also produce 1 January 1970 exactly.
Is a Unix timestamp the same as UTC?
Not quite the same thing, but closely tied. UTC is a time standard you can display as a date and time; a Unix timestamp is a count of seconds measured from a fixed UTC moment. Converting a timestamp to UTC gives you its date and time with no offset applied.
A Unix timestamp is just a number of seconds since 1970 in UTC. Keep track of whether you're holding seconds or milliseconds, store instants in UTC, and apply time zones only when a person needs to read the date — those three habits prevent nearly every timestamp bug you're likely to meet.
Ready to put this into practice?
Convert a Timestamp Free