Unix timestamps explained

A Unix timestamp is just one number: the count of seconds since 1 January 1970, UTC. That simplicity is why it is everywhere — and why the bugs around it (seconds vs milliseconds, timezone assumptions, the 2038 limit) keep showing up decades later.

The one definition that matters

A Unix timestamp measures elapsed seconds since the epoch — 1970-01-01 00:00:00 UTC — not counting leap seconds. Because it is anchored to UTC, the same number means the same instant everywhere on Earth. 1700000000 is 2023-11-14 22:13:20 in UTC, but 2023-11-15 06:13:20 in Beijing and 2023-11-14 14:13:20 in New York. One number, many local renderings — the number itself never changes.

This is exactly why timestamps are the right choice for storing moments: databases, logs and APIs all compare instants without ever arguing about timezones.

Seconds vs milliseconds: the classic silent bug

JavaScript's Date.now() returns milliseconds. Unix convention and most backend systems use seconds. Mixing them up does not throw an error — it produces dates centuries in the future or past:

  • Seconds 1700000000 read as milliseconds → 1970-01-20 (17 days after the epoch).
  • Milliseconds 1700000000000 read as seconds → year 55885.

A quick sanity check: a seconds timestamp is 10 digits (until 2286), a milliseconds timestamp is 13 digits (until 2286). If a parsed date looks absurd, count the digits first.

Where timezones actually apply

A timestamp has no timezone. A formatted date string does. The bug pattern looks like this:

  • Server stores 2026-11-19 00:00:00 intending "midnight in Beijing" but the parser assumes UTC.
  • The stored value is off by eight hours — invisible until someone sorts, sums or compares across days.

The fix is consistency: store instants as timestamps (or ISO 8601 with explicit offsets like 2026-11-19T00:00:00+08:00), and only convert to local time at the display layer. Never parse "2026-11-19 00:00:00" without knowing which zone it refers to.

The 2038 problem

A signed 32-bit integer can count up to 2,147,483,647 seconds — which runs out on 19 January 2038, 03:14:07 UTC. Systems with 32-bit time fields (some embedded firmware, older file formats, certain databases) will wrap around to December 1901.

If you work with embedded systems or old binary formats, check how they store time. Everywhere else, 64-bit timestamps are already the norm, and the limit is now measured in hundreds of billions of years.

Practical tips

  • Always name your units. A field called expires is a bug waiting to happen; expires_at_sec is not.
  • Test around boundaries. Midnight UTC, leap-year 29 February, and the last day of the month are where date code fails.
  • Prefer the ISO 8601 string in human-facing APIs, timestamps in machine-facing ones — or expose both and let the caller pick.
  • When debugging, convert the raw number in the timestamp tool before touching any code — half the time the number itself tells you which unit was meant.