Unix timestamps & UTC

Why storing time as a single number avoids almost every timezone bug, and the 2038 problem you should know about.

What a Unix timestamp is

A Unix timestamp is the number of seconds (or milliseconds) since the epoch: 1970-01-01 00:00:00 UTC. It is timezone-neutral: the same instant has the same timestamp everywhere on Earth.

2026-09-17 12:00:00 UTC  β†’  1787112000
2026-09-17 08:00:00 EDT    β†’  1787112000   (same instant!)
2026-09-17 20:00:00 +08:00  β†’  1787112000

Store UTC, display local

πŸ’‘
The robust pattern: keep time in UTC (or as a timestamp) internally, and convert to the user's local zone only at the display layer. Never store 'local time' without the zone.
const now = Math.floor(Date.now() / 1000); // seconds since epoch
const d = new Date();
console.log(d.toISOString()); // always UTC: 2026-09-17T12:00:00.000Z
from datetime import datetime, timezone
now = datetime.now(timezone.utc)
print(int(now.timestamp()))      # epoch seconds
print(now.isoformat())           # 2026-09-17T12:00:00+00:00

The 2038 problem

Systems that store the timestamp as a signed 32-bit integer overflow on 2038-01-19. Modern languages use 64-bit values, but legacy C code and some embedded systems still need migration.

⚠️
If you maintain older C/C++ services, audit time_t usage now β€” 2038 is closer than it looks.

FAQ

Seconds or milliseconds?
Unix is defined in seconds; JavaScript's Date uses milliseconds (Date.now() returns ms). Know which one your API expects.
Is a timestamp affected by leap seconds?
UTC includes leap seconds; POSIX time ignores them, so a timestamp is a close approximation, not an astronomically exact count.

Time zones & UTC offsets JSON basics

Last refreshed 2026-09-17.