Skip to main content

What is epoch time (Unix time), and how do you convert it?

6 min read

Epoch time is the number of seconds since 1 January 1970 UTC. Here's what that means, why it's everywhere, and how to convert it to a date.

Epoch time (also called Unix time or a Unix timestamp) is the number of seconds that have passed since 00:00:00 UTC on 1 January 1970. That instant is “the epoch”, the zero point everything is measured from. As you read this, the value is somewhere around 1.79 billion.

Why count seconds from 1970?

A moment in time is otherwise surprisingly hard for a computer to store. “9 a.m.” means different things in different places; date strings come in dozens of formats; calendars have leap years and varying month lengths. A single integer sidesteps all of it. To compare two moments, a program just compares two numbers. To find the gap between them, it subtracts. There is no time zone to reconcile and no text to parse first.

The 1970 starting point is a historical accident: it was a round, recent date when the Unix operating system was being built, and it stuck. The count deliberately ignores leap seconds, which keeps the arithmetic simple.

Seconds vs. milliseconds

This trips people up constantly. Unix time is traditionally in seconds, but JavaScript and many APIs use milliseconds, the same count times 1000. A quick way to tell them apart today: a seconds value has about 10 digits, a milliseconds value about 13.

1700000000       → seconds      (Nov 2023)
1700000000000    → milliseconds (same instant)

Converting a timestamp to a date

In the two most common languages:

// JavaScript: note the * 1000 for milliseconds
new Date(1700000000 * 1000).toISOString();
// "2023-11-14T22:13:20.000Z"

# Python
from datetime import datetime, timezone
datetime.fromtimestamp(1700000000, tz=timezone.utc)
# 2023-11-14 22:13:20+00:00

Going the other way, Math.floor(Date.now() / 1000) in JavaScript or int(time.time()) in Python gives you the current epoch time in seconds.

The year 2038 problem

Older systems stored epoch time in a signed 32-bit integer, which runs out of room at 03:14:07 UTC on 19 January 2038. The next second overflows into a negative number, throwing the date back to 1901. The remedy, already standard on modern platforms, is a 64-bit integer, which pushes the limit hundreds of billions of years into the future.

To read or generate an epoch value without doing the arithmetic by hand, use our free Unix timestamp converter. It handles seconds and milliseconds, shows the result in UTC and your local time, and converts in both directions.

Frequently asked questions

What is epoch time?
Epoch time, also called Unix time, is the number of seconds that have elapsed since 00:00:00 UTC on 1 January 1970, not counting leap seconds. It is a single integer that represents a moment in time, independent of time zone.
What is epoch time used for?
It is a compact, unambiguous way to store and compare moments. Databases, log files, APIs, JWTs and file systems use it because comparing two integers is trivial and there is no time-zone or formatting ambiguity to resolve first.
How do I convert a Unix timestamp to a date?
Multiply or divide to get seconds, then apply it to your language's date type: in JavaScript, new Date(seconds * 1000); in Python, datetime.utcfromtimestamp(seconds). Or paste the number into an online timestamp converter to see it instantly.
What is the 2038 problem?
Systems that store epoch time in a signed 32-bit integer can only count up to 03:14:07 UTC on 19 January 2038. One second later the value overflows to a negative number. The fix is to store the timestamp in a 64-bit integer, which most modern systems already do.