Convert Unix timestamps in JavaScript with live parser and copy-ready Date snippets. Seconds vs milliseconds handled.
Smart Universal Parser
// Paste Unix seconds/ms, ISO 8601, RFC 2822, or a human date.
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.
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:
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.
The Date constructor expects milliseconds, so multiply seconds by 1000. toISOString() always prints UTC with a trailing Z:
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; // 1715429912So 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.
Intl.DateTimeFormatFor display, avoid hand-built strings. Intl.DateTimeFormat handles locales, 12/24-hour clocks, and IANA timezones natively in browsers and Node.js:
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.
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:
const toMs = (t) => (String(Math.trunc(t)).length <= 10 ? t * 1000 : t);
new Date(toMs(1715429912)).toISOString(); // works for s or msThe 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.
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.
new Date('2024-05-11T12:18:32') is parsed as local time, while a date-only string like '2024-05-11' is parsed as UTC. Always include Z or an offset in machine data.new Date(2024, 4, 11) is May 11, not April. Date.UTC(2024, 4, 11) has the same rule.setDate() and friends mutate in place. Clone with new Date(d) before changing a shared value.createdAtMs.Use Math.floor(Date.now() / 1000) for seconds. Date.now() on its own returns milliseconds.
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.
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.
Use Intl.DateTimeFormat with a timeZone option such as 'Europe/Paris' or 'America/New_York'. It applies daylight-saving rules automatically.
Yes. toISOString() always outputs UTC with a Z suffix, whatever the user’s local timezone. Use Intl.DateTimeFormat for local display.
No. The parser and snippet generator run entirely in your browser; nothing you paste leaves the tab.