Get a timestamp in JavaScript

javascript

Updated August 29, 2026

Date.now() returns the current Unix timestamp in milliseconds:

const milliseconds = Date.now();
const seconds = Math.floor(milliseconds / 1000);

Use milliseconds when working with JavaScript Date values. Convert to seconds only when an API explicitly expects seconds. To turn a timestamp back into a date, use new Date(milliseconds) or new Date(seconds * 1000).

A Unix timestamp represents an instant, so it does not contain a time zone or a human calendar format. The system clock can be adjusted, which makes Date.now() unsuitable for measuring elapsed time precisely. For durations inside one process, use performance.now() in a browser or Node's node:perf_hooks performance API. If timestamps cross a network boundary, document the unit and use an unambiguous format such as ISO 8601 where appropriate.

Sources

related.

Ruslan Osipov

Ruslan Osipov

About the author