TimeStampConverter.org
Developer Guide
Unix Timestamp Resource

Unix Timestamp in JavaScript

Convert Unix timestamps in JavaScript, including Date.now, seconds, milliseconds, ISO strings, UTC output, and common browser pitfalls.

Updated August 4, 2026 8 min read

Overview

JavaScript stores Date values as milliseconds since the Unix epoch. To convert Unix seconds into a JavaScript Date, multiply by 1000. To get Unix seconds from the current time, divide Date.now() by 1000 and round down.

This guide focuses on practical implementation choices: how values should be stored, how they should cross API boundaries, and where developers most often introduce timezone or precision bugs. The safest pattern is to keep the stored value unambiguous, document the unit, and format the date only when it reaches a human-facing interface.

When to use it

Use JavaScript conversion at the UI edge: rendering API timestamps, preparing client-side form values, building countdowns, and debugging browser event times.

For production systems, also consider how the value will be indexed, logged, serialized, and read by other teams. A timestamp field that is obvious in one programming language can become ambiguous when it is consumed by JavaScript, SQL, mobile clients, or third-party integrations.

Developer examples

Use examples like this as a starting point, then adapt the timezone and precision to your application contract.

const unixSeconds = Math.floor(Date.now() / 1000);
const date = new Date(unixSeconds * 1000);
console.log(date.toISOString());

Common pitfalls

The Date constructor interprets numbers as milliseconds. Passing seconds directly creates a date near 1970.

Most timestamp bugs come from hidden assumptions: local time treated as UTC, seconds treated as milliseconds, formatted strings parsed without offsets, or narrow integer columns copied from old examples. Add tests for boundary dates and document the expected unit beside every external timestamp field.

FAQ

Does Date.now return seconds?

No. Date.now returns milliseconds. Divide by 1000 for Unix seconds.

How do I output UTC?

Use toISOString() or toUTCString() for UTC-formatted output.