DEVELOPER GUIDE

Unix timestamps: seconds vs. milliseconds

Avoid dates in 1970 and far-future years by choosing the correct timestamp unit.

4 min read•DevToolbox editorial

One epoch, two common scales

Unix timestamps describe time relative to 1970-01-01T00:00:00Z. APIs often use seconds, while JavaScript Date uses milliseconds. The same instant differs by a factor of 1,000 between those units.

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

Do not infer units from length alone

Contemporary positive timestamps commonly have 10 digits in seconds or 13 in milliseconds, but that is only a heuristic. Older dates, fractional values, and different ranges break this rule. Prefer the API specification or an explicit unit selector.

UTC and local time describe the same instant

UTC does not change with the visitor’s timezone. Local rendering does. For portable date strings, include Z for UTC or an explicit offset such as +05:00. A bare date-time string can be interpreted differently across environments.

Convert with care around negative values

Dates before the epoch have negative timestamps. When reducing milliseconds to whole seconds, decide whether your application needs flooring or truncation. This converter floors to the containing Unix second and also displays the exact millisecond value.

Put it into practice with a free tool that runs in your browser.
Open Timestamp Converter