Unix timestamps: seconds vs milliseconds

Published: 2026-07-20

Why APIs mix 10-digit and 13-digit epoch values, how to tell them apart, and how to convert safely in JavaScript and logs.

A Unix timestamp counts seconds (sometimes milliseconds) since 1970-01-01 00:00:00 UTC — the Unix epoch. JWT exp, database created_at, and JavaScript Date.now() all use the same idea with different scales, which causes off-by-1000 bugs in dashboards and migrations.

Seconds vs milliseconds

Scale Digits (circa 2026) Example API
Seconds 10 JWT exp, PostgreSQL extract(epoch ...), Linux date +%s
Milliseconds 13 JavaScript Date.now(), MongoDB ISODate internals

Quick heuristic for modern dates:

  • 10 digits → multiply by 1000 before new Date() in JS.
  • 13 digits → pass directly to new Date(ms).

Values around 1_700_000_000 are seconds (year ~2023). Values around 1_700_000_000_000 are milliseconds.

JavaScript conversion

const sec = 1_700_000_000;
const d = new Date(sec * 1000);

const ms = 1_700_000_000_000;
const d2 = new Date(ms);

Date.parse('2026-07-20') accepts ISO strings; epoch integers need explicit scale.

Time zones and display

Epoch values are UTC instants. Converting to “local wall time” uses the viewer’s time zone (Intl, toLocaleString). Scheduling cron in local time but storing UTC epoch is correct — document which zone your UI shows.

Fractional seconds

Some logs use 1700000000.123 (seconds with decimals). JSON numbers may lose precision above 2^53; for sub-millisecond science data prefer string or integer nanoseconds in the wire format.

Try it locally

The Unix Timestamp Converter accepts seconds or milliseconds (with Auto detection), ISO strings, and shows UTC, local, and ISO output — without sending values to a server.

Pair with the Timezone Converter when debugging multi-region systems.

Related reading

All learn articles