Skip to content

The Unix Epoch: Why time started in 1970

I was looking at a bug report the other day where a user's "Join Date" was listed as December 31, 1969.

I knew they hadn't joined the app before the internet existed, so I knew exactly what happened: somewhere in our database, their join date was set to 0.

In the world of computers, 0 isn't just a number—it's January 1, 1970.

The Big Picture: Counting Seconds

Computers don't really understand "Tuesday at 4:30 PM." They are much better at counting.

So, back in the early days of Unix, the engineers decided to pick a starting point (the Epoch) and just count the number of seconds that have passed since then.

[ Jan 1, 1970 ] ----(+1 second)----> [ Jan 1, 1970 00:00:01 ]
      (0)                                     (1)

Today, as I write this, that count is somewhere around 1,714,000,000.


Wait, but why 1970?

Why not 1900? Or the year 0?

There isn't a massive technical reason. The Unix creators (Ken Thompson and Dennis Ritchie) just needed a convenient, recent date. At the time they were designing it in the late 60s, 1970 was "the future."

If they had picked 1900, we would have had to waste bits representing the 70 years that hadn't happened yet!


The Problem: January 19, 2038

Remember how I said integers have limits? Most older systems store the Epoch time as a 32-bit signed integer.

As we saw in my Magic Numbers post, the maximum value for a 32-bit integer is 2,147,483,647.

On January 19, 2038, the number of seconds since 1970 will hit that limit. One second later, the number will "roll over" and become -2,147,483,648.

Suddenly, every computer running 32-bit code will think it is December 13, 1901.


Common gotchas

  • I always forget about time zones. The Epoch is always in UTC. If your computer shows "Dec 31, 1969," it's because you are in a time zone behind UTC (like New York), so 0 in London is -18000 (5 hours earlier) for you!
  • Watch out for Milliseconds: JavaScript and Java use milliseconds since the Epoch, while Python and Ruby use seconds. If your date looks like it's in the year 50,000, you probably multiplied by 1000 by mistake.

Try it yourself

You can see the current Unix timestamp in your terminal right now:

date +%s

And you can convert a number back to a date:

date -r 0
# Output: Thu Jan  1 00:00:00 UTC 1970

Further reading

— Nadeem 🕰️

Comments