Unix Timestamps Explained: Epoch Time for Humans

Unix Timestamps Explained: Epoch Time for Humans

What a Unix timestamp is, why it counts from 1970, seconds vs milliseconds, time zones, the year 2038 problem, and how to convert timestamps quickly.

Open a database table, an API response or a log file and you will often find dates written as long numbers such as 1791536400. That is a Unix timestamp. It is one of the simplest and most useful ways computers record time, as long as you know how to read it.

What a Unix timestamp is

A Unix timestamp is the number of seconds that have passed since 00:00:00 UTC on 1 January 1970, a moment known as the Unix epoch. The date was simply a convenient round starting point when the Unix operating system was being developed.

Because it is a single number, a timestamp is easy to store, compare and sort: a bigger number is always later. It also has no time zone. The same timestamp means the same instant everywhere on Earth.

Seconds or milliseconds?

The classic Unix timestamp counts seconds and currently has 10 digits. JavaScript's Date.now() and many APIs use milliseconds instead, which gives 13 digits. Mixing them up is the most common timestamp bug: a millisecond value read as seconds lands tens of thousands of years in the future, and a seconds value read as milliseconds lands in January 1970.

A quick rule: count the digits. Ten digits is seconds, thirteen is milliseconds.

Time zones

A timestamp itself is always UTC. Time zones only come into play when you turn it into a readable date. That is a strength: store timestamps, and convert to the visitor's local time only when you display them. Storing local times without a zone is how you end up with events that shift by an hour when daylight saving time changes.

The year 2038 problem

Older systems store the timestamp in a signed 32-bit integer, which can only count up to 2,147,483,647 seconds. That limit is reached at 03:14:07 UTC on 19 January 2038, after which such a counter overflows. Modern operating systems and languages use 64-bit timestamps, which will not run out for billions of years, but old embedded devices and legacy database columns can still be affected.

Negative timestamps

Dates before 1970 are simply negative numbers. For example, -86400 is 31 December 1969. Not every system handles them, so test before you rely on them for historical dates.

Getting the current timestamp in code

  • JavaScript: Math.floor(Date.now() / 1000)
  • PHP: time()
  • Python: int(time.time())
  • MySQL: UNIX_TIMESTAMP()
  • Linux shell: date +%s

Converting timestamps quickly

When you are debugging, you rarely want to write code just to read a date. The Timestamp Converter turns a Unix timestamp into a readable date and a date back into a timestamp. If you need to work out the gap between two dates instead, the Days Between Dates Calculator does that, and the World Clock shows the current time and UTC offset around the world.

Choose which cookies SEOpeck may use. You can change this at any time from "Cookie settings" at the bottom of every page.

Your tools

    Saved in this browser only. Nothing is sent to us.