Unix timestamps in JavaScript

Everything JavaScript needs for Unix timestamps: the current epoch time in seconds and milliseconds, timestamp-to-date and date-to-timestamp conversion, and ISO 8601 parsing. JavaScript's native unit is milliseconds, so the classic bug is feeding epoch seconds straight into new Date() and landing in January 1970. There's a live converter at the bottom for checking any value the snippets produce.

Get the current Unix timestamp

const millis = Date.now();                    // 1700000000000
const seconds = Math.floor(Date.now() / 1000); // 1700000000

Convert a timestamp to a Date

const date = new Date(1700000000 * 1000); // seconds → ms first
date.toISOString(); // "2023-11-14T22:13:20.000Z"

new Date(1700000000) is 20 days after the 1970 epoch. If a timestamp is 10 digits, multiply by 1000.

Convert a Date to a timestamp

const millis = date.getTime();
const seconds = Math.floor(date.getTime() / 1000);

Parse an ISO 8601 string

const date = new Date("2023-11-14T22:13:20Z");
date.toLocaleString("en-US", { timeZone: "Asia/Tokyo" });

A date-only string like "2023-11-14" parses as midnight UTC, but "2023-11-14T00:00" (no zone) parses as local time. That's a genuine spec quirk.

Check a value

Detected: Unix timestamp (seconds)

Your timezone

UTC · GMT+00:00 · UTC

Tue, Nov 14, 2023, 10:13:20 PM

Common formats

UTC

Tue, Nov 14, 2023, 10:13:20 PM

ISO 8601

2023-11-14T22:13:20.000Z

Unix (seconds)

1700000000

Unix (millis)

1700000000000

Relative

World clock

Los Angeles PST

Tue, Nov 14, 2023, 02:13:20 PM

GMT-08:00

Chicago CST

Tue, Nov 14, 2023, 04:13:20 PM

GMT-06:00

New York EST

Tue, Nov 14, 2023, 05:13:20 PM

GMT-05:00

London GMT

Tue, Nov 14, 2023, 10:13:20 PM

GMT+00:00

Paris CET

Tue, Nov 14, 2023, 11:13:20 PM

GMT+01:00

Kolkata IST

Wed, Nov 15, 2023, 03:43:20 AM

GMT+05:30

Shanghai CST

Wed, Nov 15, 2023, 06:13:20 AM

GMT+08:00

Tokyo JST

Wed, Nov 15, 2023, 07:13:20 AM

GMT+09:00

Sydney AEDT

Wed, Nov 15, 2023, 09:13:20 AM

GMT+11:00

Common questions

Why does my date show 1970?
You passed epoch seconds where milliseconds were expected. new Date() takes milliseconds; multiply a 10-digit timestamp by 1000.
How do I get epoch seconds like other languages?
Math.floor(Date.now() / 1000). There's no built-in seconds API; the ecosystem settled on milliseconds because that's what Date stores.
Is Date.parse() safe for arbitrary strings?
Only for ISO 8601 and RFC 2822 forms; anything else is engine-specific. Parse known formats explicitly, or use the Temporal API where available.

Related converters