JavaScript Unix Timestamp Converter

Convert Unix timestamps in JavaScript with live parser and copy-ready Date snippets. Seconds vs milliseconds handled.

⏱ UnixLi — Live Tool All processing local · No data sent
—
unix seconds · now

Smart Universal Parser

// Paste Unix seconds/ms, ISO 8601, RFC 2822, or a human date.

Developer Snippets

// Copy-ready code — current timestamp injected automatically.

PythonPHPGoRust

Unix timestamps in JavaScript

JavaScript measures time in milliseconds since the Unix epoch, while most APIs, databases, and JWT claims use seconds. Almost every timestamp bug in front-end and Node.js code comes from that factor of 1000. The live parser above accepts seconds, milliseconds, ISO 8601, and RFC 2822 and shows every representation side by side. The snippet panel below it generates copy-ready JavaScript with the current timestamp filled in. Everything runs in your tab; no value you paste is uploaded.

Getting the current time: Date.now() and getTime()

Date.now() returns the current time as an integer number of milliseconds. new Date().getTime() and new Date().valueOf() return the same number from a Date object. To get Unix seconds, divide by 1000 and drop the fraction:

JavaScript
const ms = Date.now();                   // e.g. 1715429912000
const seconds = Math.floor(ms / 1000);   // 1715429912
const alsoMs = new Date().getTime();     // same unit as Date.now()

Use Math.floor rather than Math.round so a timestamp never points half a second into the future. That matters when comparing against a JWT exp or an API’s “not before” check.

Converting Unix seconds to a Date and back

The Date constructor expects milliseconds, so multiply seconds by 1000. toISOString() always prints UTC with a trailing Z:

JavaScript
const d = new Date(1715429912 * 1000);
d.toISOString();                          // "2024-05-11T12:18:32.000Z"
Math.floor(d.getTime() / 1000);           // 1715429912
Date.parse('2024-05-11T12:18:32Z') / 1000; // 1715429912

So 1715429912 is Saturday, May 11, 2024 at 12:18:32 UTC. Forget the multiplication, new Date(1715429912), and you get 1970-01-20T20:30:29.912Z, the classic “why is my date in January 1970?” bug.

Formatting with Intl.DateTimeFormat

For display, avoid hand-built strings. Intl.DateTimeFormat handles locales, 12/24-hour clocks, and IANA timezones natively in browsers and Node.js:

JavaScript
new Intl.DateTimeFormat('en-US', {
  dateStyle: 'full', timeStyle: 'long', timeZone: 'America/New_York',
}).format(new Date(1715429912 * 1000));
// "Saturday, May 11, 2024 at 8:18:32 AM EDT"

For “3 minutes ago” style text, Intl.RelativeTimeFormat formats a signed number with a unit. The generated snippet shows both.

Seconds vs milliseconds: a quick detector

Current Unix seconds have 10 digits; milliseconds have 13. The parser uses the same rule. It also recognizes 16-digit microseconds, which some logging systems emit. In code, a defensive helper is simple:

JavaScript
const toMs = (t) => (String(Math.trunc(t)).length <= 10 ? t * 1000 : t);
new Date(toMs(1715429912)).toISOString(); // works for s or ms

The full explanation, including why 10 digits holds until the year 2286, is in Unix seconds vs milliseconds. For a longer tutorial with parsing, formatting, and time zones, read Unix timestamps in JavaScript.

Measuring durations: don’t use Date.now()

Wall-clock time can jump when the system clock syncs or a user changes it. For benchmarks and timeouts, use performance.now() in browsers and Node.js, or process.hrtime.bigint() in Node.js. Both are monotonic and ignore clock adjustments. Keep Date.now() for timestamps you store or send to other systems.

Common JavaScript date pitfalls

Frequently asked questions

How do I get the current Unix timestamp in JavaScript?

Use Math.floor(Date.now() / 1000) for seconds. Date.now() on its own returns milliseconds.

What is the difference between Date.now() and getTime()?

Both return milliseconds since the Unix epoch. Date.now() is a static call for the current moment; getTime() reads the value stored in an existing Date object.

Why does new Date(1715429912) show January 1970?

The constructor expects milliseconds, so the seconds value is read as about 20 days after the epoch. Multiply by 1000: new Date(1715429912 * 1000) gives 2024-05-11T12:18:32.000Z.

How do I display a timestamp in a specific timezone?

Use Intl.DateTimeFormat with a timeZone option such as 'Europe/Paris' or 'America/New_York'. It applies daylight-saving rules automatically.

Is toISOString() always UTC?

Yes. toISOString() always outputs UTC with a Z suffix, whatever the user’s local timezone. Use Intl.DateTimeFormat for local display.

Does this page send my timestamps anywhere?

No. The parser and snippet generator run entirely in your browser; nothing you paste leaves the tab.

Related tools