Math & time

Unix Timestamp Seconds vs Milliseconds: Avoid the 1970 Date Bug

Identify timestamp units explicitly, convert batches to UTC and diagnose dates near 1970 caused by a thousandfold unit mismatch.

Photorealistic editorial photo for Unix Seconds Vs Milliseconds
Math & time · Practical ideas for your next build

A timestamp is incomplete without its unit. Unix time is often expressed in seconds, while JavaScript Date expects milliseconds when constructed from a number. Passing a seconds value directly to that constructor shrinks the intended interval by a factor of one thousand and often produces a date near 1970. The reverse mistake pushes a value far into the future. Confirm the producing system’s contract before converting a log column.

Convert the unit before constructing the date

Multiply integer seconds by one thousand to obtain milliseconds, then interpret that value as an instant relative to the Unix epoch. Millisecond inputs need no multiplication. Choose the unit explicitly instead of relying on the familiar ten-digit or thirteen-digit appearance of recent timestamps. Historical values, negative values and distant future dates break that heuristic. Our batch converter records the selected unit next to each original input so the report remains understandable after it is copied elsewhere.

Keep UTC instants separate from local display

A numeric Unix timestamp represents an instant, not a regional wall-clock date with an attached time zone. The same instant can be displayed as different local dates or clock times in different regions. The converter returns ISO UTC strings ending in Z to make its display convention clear. If you need a local calendar interpretation, convert that instant using an explicit IANA time zone. Do not manually add a fixed offset when daylight-saving or historical regional rules can affect the requested date.

Check precision, range and failed lines

Large integers can exceed exact JavaScript numeric precision before a date is constructed. The batch converter requires both the input integer and its millisecond value to remain safe integers, then checks the supported Date range. It also rejects fractional inputs rather than silently truncating them. A malformed line stops with its original line number, preserving the relationship between source and report. For datasets with sub-millisecond precision, retain the original value and use a representation that explicitly supports the required precision.

Worked example

EXAMPLE
Seconds:      1700000000
Milliseconds: 1700000000000
UTC:          2023-11-14T22:13:20.000Z

Can the number of digits reliably determine timestamp units?

No. Digit count is a clue for familiar recent values, not a complete contract. Read the source format or select the unit explicitly.

Reference and further reading

Read the official documentation ↗