Unix Timestamp in JavaScript

JavaScript's Date API works in milliseconds internally. Use Date.now() to get the current timestamp — divide by 1000 for seconds, or keep as-is for milliseconds.

Ad

Code Examples

Current timestamp (seconds)

Math.floor(Date.now() / 1000);

Returns the current Unix timestamp in seconds. Most REST APIs, JWT tokens, and databases expect this 10-digit format.

Current timestamp (milliseconds)

Date.now();

Returns milliseconds since epoch. This is the native JS format — used by setTimeout, performance.now(), and most browser APIs.

Convert Date string to timestamp

Math.floor(new Date("2024-06-15T12:00:00Z").getTime() / 1000);

Parse any ISO 8601 date string and convert it to a Unix timestamp in seconds.

Convert timestamp back to Date

new Date(timestamp * 1000).toISOString();

Multiply by 1000 to convert seconds back to milliseconds before passing to the Date constructor.

Node.js — process.hrtime (high resolution)

const [sec] = process.hrtime();
console.log(sec); // seconds since an arbitrary time

For high-resolution timing in Node.js. Note: hrtime is relative, not Unix epoch. Use Date.now() for epoch timestamps.

Note

JavaScript uses milliseconds internally — unlike most other languages that default to seconds. When debugging API payloads, a 10-digit number is seconds; a 13-digit number is milliseconds. The converter at the top of this page auto-detects both.

Ad

Need to convert a specific timestamp? Use the live converter — paste any epoch value and see the human-readable date instantly.

← Open the converter