UnixTime / Reference

Unix time in JavaScript

Use Date.now(), convert timestamps to ISO dates and avoid seconds-versus-milliseconds errors in JavaScript.

Get the current Unix timestamp in JavaScript

Date.now() returns the number of milliseconds since the Unix epoch. Many APIs ask for Unix seconds instead. Use Math.floor(Date.now() / 1000) for that representation.

const nowMilliseconds = Date.now();
const nowSeconds = Math.floor(Date.now() / 1000);
console.log(nowSeconds); // Current Unix timestamp, in seconds

Convert Unix seconds into an ISO 8601 date

The JavaScript Date constructor expects milliseconds. Multiplying an epoch value in seconds by 1,000 is essential. toISOString() returns the UTC timestamp, marked with a trailing Z.

const unixSeconds = 1735689600;
const utcDate = new Date(unixSeconds * 1000);
console.log(utcDate.toISOString()); // "2025-01-01T00:00:00.000Z" 

Convert a date to Unix seconds

A string ending in Z is interpreted as UTC. An ISO date-time string without a time-zone offset may be interpreted as the viewer's local time. Explicitly include the offset if you want consistent results across browsers and servers.

const utc = new Date("2025-01-01T00:00:00Z");
const seconds = Math.floor(utc.getTime() / 1000);
console.log(seconds); // 1735689600

Display the same instant in another time zone

Formatting a timestamp for a locale does not change the underlying Unix instant. Use Intl.DateTimeFormat with an IANA time zone. This is particularly important around daylight-saving transitions, when local times can be repeated or skipped.

const instant = new Date(1735689600 * 1000);
const formatter = new Intl.DateTimeFormat("en-GB", {
  dateStyle: "medium", timeStyle: "medium",
  timeZone: "Europe/Brussels"
});
console.log(formatter.format(instant));

Common mistakes and precision limits

Our UnixTime converter performs the conversion locally in the browser, and you can choose seconds, milliseconds, microseconds or nanoseconds explicitly.

Reference: MDN JavaScript Date documentation.