elefcode
← All guides

Dev Basics · 4 min read

Unix Timestamps Explained: Epoch Time, Seconds vs Milliseconds

A Unix timestamp is the number of seconds since 00:00:00 UTC on 1 January 1970 — the "epoch". It is how databases, logs, JWTs, and APIs most often store a moment in time, because a single number is easy to compare, sort, and send.

Try it yourself with the related tool.

Convert a timestamp →

Advertisement

Seconds or milliseconds?

Most systems count seconds, but JavaScript's Date.now() and Java count milliseconds. Count the digits: a current timestamp in seconds has 10 digits (around 1.8 billion), and in milliseconds it has 13. Mixing them up produces dates in 1970 or tens of thousands of years in the future — a sure sign of a units bug.

Timestamps have no time zone

A timestamp names one instant, the same everywhere on Earth. Time zones only matter when you display it. Store and compare timestamps (or ISO 8601 strings in UTC, such as 2026-10-29T14:00:00Z), and convert to the user's local time at the last moment. Storing local times without an offset is the root of most daylight-saving bugs.

Leap seconds and precision

Unix time ignores leap seconds — every day is exactly 86,400 seconds — which keeps arithmetic simple. For sub-second precision, systems use milliseconds, microseconds, or a fractional part. When converting, make sure you do not silently drop that fraction.

The year 2038 problem

A signed 32-bit integer can hold timestamps only up to 03:14:07 UTC on 19 January 2038. Systems that still store time that way will overflow and wrap to 1901. Modern platforms use 64-bit integers, but old databases, file formats, and embedded devices are worth checking.

Related guides