Skip to content

What is a Unix timestamp and how do you convert it?

What a Unix timestamp counts, how to tell seconds from milliseconds, why 2038 matters, and how to convert timestamps to dates in any language.

Guide5 min readUpdated

A Unix timestamp (also called epoch time or POSIX time) is the number of seconds that have passed since 1 January 1970 at 00:00:00 UTC, a moment known as the Unix epoch. For example, 1700000000 is 14 November 2023, 22:13:20 UTC. Because it's a single number in UTC, it's easy to store, sort and compare, and it means the same moment in every time zone, which is why APIs, databases, logs and JWTs use it.

Seconds, milliseconds and more

Not every system counts in seconds. The quickest way to tell is the number of digits for a current date:

Seconds10 digits1700000000PHP time(), Python int(time.time()), JWT exp
Milliseconds13 digits1700000000000JavaScript Date.now(), Java System.currentTimeMillis()
Microseconds16 digits1700000000000000Some logging and analytics systems
Nanoseconds19 digits1700000000000000000Go's UnixNano(), tracing systems

Mixing them up is a classic bug: reading milliseconds as seconds lands you tens of thousands of years in the future, and reading seconds as milliseconds lands you in January 1970.

In JavaScript

Date.now();                          // current time in milliseconds
Math.floor(Date.now() / 1000);       // current time in seconds

new Date(1700000000 * 1000).toISOString();  // "2023-11-14T22:13:20.000Z"
Math.floor(new Date("2024-01-05T09:30:00Z").getTime() / 1000);  // 1704447000
JavaScript dates work in milliseconds, so multiply or divide by 1000.

In Python

import time
from datetime import datetime, timezone

int(time.time())                                         # current time in seconds
datetime.fromtimestamp(1700000000, tz=timezone.utc)      # 2023-11-14 22:13:20+00:00
int(datetime(2024, 1, 5, 9, 30, tzinfo=timezone.utc).timestamp())  # 1704447000
Always pass tz=timezone.utc; without it Python uses the computer's local time zone.

In the terminal

date +%s                      # current timestamp
date -u -d @1700000000        # Linux (GNU date)
date -u -r 1700000000         # macOS (BSD date)

The year 2038 problem

Many older systems stored timestamps as a signed 32-bit integer, whose largest value is 2147483647: 19 January 2038 at 03:14:07 UTC. One second later the number overflows and wraps around to 1901. Modern systems use 64-bit timestamps, which last for billions of years, but embedded devices, old databases and file formats can still be affected. If you store timestamps yourself, use a 64-bit column.

Converting timestamps online

The Epoch Converter turns a timestamp into a date in UTC, your own time zone, ISO 8601 and more, or a date back into a timestamp. It detects seconds, milliseconds, microseconds and nanoseconds by length, and converts a whole list at once if you paste one per line. Decoding a token? The JWT Decoder shows exp and iat as dates automatically.

Frequently asked questions

Are Unix timestamps in UTC?

Yes. A timestamp is the number of seconds since 1 January 1970 00:00:00 UTC, so it's the same everywhere in the world. Time zones only come in when you display it as a date.

How do I know if a timestamp is in seconds or milliseconds?

Count the digits. Current dates are 10 digits in seconds (like 1760000000) and 13 in milliseconds (1760000000000). Microseconds have 16 digits and nanoseconds 19.

Can a Unix timestamp be negative?

Yes. Negative values are dates before 1970; for example -86400 is 31 December 1969 00:00:00 UTC.

Tools used in this guide

More guides