Date & Time

Unix Timestamps Explained: Epoch Time and Conversions

What a Unix timestamp is, why the epoch starts in 1970, the difference between seconds and milliseconds, and what the Year 2038 problem means.

2 min read·Updated 2026-07-11

A Unix timestamp is a single number that records a moment in time: the count of seconds since 1 January 1970 at 00:00:00 UTC. That reference instant is called the epoch. Because it is just a number, it is compact, sortable and completely free of time-zone ambiguity, which is exactly why databases and APIs use it constantly.

Why 1970?

The Unix operating system was being designed in the late 1960s and early 1970s, and its authors needed a simple origin. 1 January 1970 was a convenient recent date. A signed 32-bit integer can hold roughly 68 years of seconds around that point, comfortably covering the era when the system was built.

Seconds vs milliseconds

  • Seconds — the original Unix value. The timestamp 1000000000 means 2001-09-09. JavaScript, however, uses milliseconds, so the same moment is 1000000000000.
  • Milliseconds — 1,000 times larger. JavaScript's Date.now() returns milliseconds, and Java's System.currentTimeMillis() does too.
  • Microseconds and nanoseconds — used by high-precision systems. PostgreSQL can store microseconds, and some Linux clocks expose nanoseconds.

A quick way to tell them apart: a 10-digit number is seconds, a 13-digit number is milliseconds. Get it wrong and your date lands in 1970 or in the year 55000.

The Year 2038 problem

Many older systems store timestamps as signed 32-bit integers. The largest value such an integer holds is 2,147,483,647, which corresponds to 03:14:07 UTC on 19 January 2038. One second later the value overflows and, on unpatched systems, flips to a negative number and a date in 1901. The fix is to move to 64-bit storage, which pushes the limit out to roughly 292 billion years.

Time-zone independence

A timestamp always refers to UTC. Your local clock shows 14:00 in New York, but the stored value is the same instant another user sees as 20:00 in Berlin. Time zones only enter the picture when you format a timestamp for display, which is why storing and comparing raw numbers avoids an entire class of bugs.

Converting in code

Most languages have ready-made helpers: JavaScript uses Math.floor(Date.now()/1000) for seconds, Python uses time.time() or datetime.timestamp(), and PHP uses the time() function. For a no-code check, paste any value into the Unix Timestamp Converter, or turn a calendar date into a number with Date to Unix Timestamp. The Current Time Now page gives you the live epoch value.

Frequently asked questions

Can a timestamp be negative? Yes. Values below zero represent dates before 1970, such as -86400 for 31 December 1969.

Do leap seconds affect timestamps? Unix time mostly ignores leap seconds, so it drifts by a second or so from astronomical time over decades.

Should I store seconds or milliseconds? Store whichever your stack standardizes on and convert only at the edges; mixing the two is the most frequent bug.

Tools used in this guide

Related guides