JavaScript · Date · Live tool below

JavaScript Timestamp
Unix time in Date and Date.now().

Convert unix timestamps in JavaScript: current time in seconds and milliseconds, seconds to Date, Date to timestamp, and formatting in any time zone. The live converter sits at the top, and every snippet below was run and checked.

Live ToolAll processing local. No data sent.
● --
Waiting for inputSeconds, milliseconds, microseconds and nanoseconds are detected from the digit count.

Quick Answers: JavaScript Timestamp

JavaScript Counts Milliseconds, Not Seconds

Quick answer: Date.now() returns milliseconds since the epoch. Divide by 1000 for Unix seconds, and multiply by 1000 when a seconds value goes into new Date().

JavaScript is the outlier among common languages: its Date object counts milliseconds, not seconds. Python time.time(), PHP time(), Go time.Now().Unix() and Rust SystemTime all hand you 10 digit seconds, while Date.now() hands you 13 digit milliseconds. That single difference causes more timestamp bugs than any other, because the arithmetic is trivial and the mistake is silent. A seconds value passed to new Date() gives a date a few minutes after the epoch, and a millisecond value sent to an API that expects seconds gives a date tens of thousands of years in the future.

The rule is short enough to memorise: going out of JavaScript, divide by 1000; going in, multiply by 1000. The converter above does both directions for you, and it names the unit it detected, so a wrong reading is visible before the value reaches your code.

Current Unix Timestamp in JavaScript

JavaScript
// Current Unix timestamp in seconds
const nowSeconds = Math.floor(Date.now() / 1000);

// Current timestamp in milliseconds
const nowMs = Date.now();

Date.now() is the fastest way to read the clock: it returns the current time in milliseconds with no object built. Math.floor(Date.now() / 1000) is the Unix timestamp in seconds, the value most APIs expect. If you need the millisecond value itself, for measuring how long something took, Date.now() alone is the answer. The live converter at the top of this page shows the same two numbers ticking every second.

Unix Timestamp to Date in JavaScript

JavaScript
// Unix seconds to date: multiply by 1000 first
const date = new Date(1715429912 * 1000);

date.toISOString();    // "2024-05-11T12:18:32.000Z"
date.toUTCString();    // "Sat, 11 May 2024 12:18:32 GMT"
date.toLocaleString(); // Local time, reader's zone

The reference value used across this site is 1715429912, which is Saturday, 11 May 2024 at 12:18:32 UTC. Multiplied by 1000 and passed to new Date(), toISOString() gives 2024-05-11T12:18:32.000Z and toUTCString() gives Sat, 11 May 2024 12:18:32 GMT. The local reading depends on the reader's zone: 08:18:32 in New York, 17:18:32 in Karachi and 21:18:32 in Tokyo, all the same instant.

Date to Unix Timestamp in JavaScript

JavaScript
// Date to Unix timestamp: divide by 1000
const ts = Math.floor(Date.parse('2024-05-11T12:18:32Z') / 1000);
console.log(ts); // 1715429912

// From a Date object
const d = new Date('2024-05-11T12:18:32Z');
Math.floor(d.getTime() / 1000); // 1715429912

Date.parse takes an ISO 8601 string and returns milliseconds, so the result is divided by 1000 and rounded down. The Z at the end of the string means UTC, and it is the part people leave out. Without it, the string is read in the browser's local time zone, so the same code gives a different timestamp in Karachi than in London. When the timestamp will be stored in a database or sent to an API, always include the designator.

JavaScript Timestamps in Other Time Zones

JavaScript
// Format one instant in another time zone
const date = new Date(1715429912 * 1000);

date.toLocaleString('en-GB', { timeZone: 'Asia/Karachi' });
// "11/05/2024, 17:18:32"

date.toLocaleString('en-GB', { timeZone: 'America/New_York' });
// "11/05/2024, 08:18:32"

Never subtract a fixed offset by hand. New York is 5 hours behind UTC in winter and 4 in summer, and the change happens on a different weekend than London's. toLocaleString with the timeZone option asks the browser's time zone database for the offset that applies to the exact date, which is the only correct way. The timezone converter on this site shows the same instant in 12 zones at once, using the same rules.

Common JavaScript Timestamp Mistakes

JavaScript Timestamp FAQs

How do I get the current unix timestamp in JavaScript?

Use Math.floor(Date.now() / 1000). Date.now() returns milliseconds since the epoch, so dividing by 1000 and rounding down gives Unix seconds. If you need the millisecond value itself, Date.now() alone is the answer. Both are shown live in the converter above, which ticks every second.

How do I convert a unix timestamp to a date in JavaScript?

Multiply the seconds by 1000 and pass them to the Date constructor: new Date(1715429912 * 1000). Then call toISOString() for the UTC reading, which is 2024-05-11T12:18:32.000Z, or toLocaleString() for the reader's local time. The multiplication is the step people forget: new Date takes milliseconds, not seconds, so a raw seconds value gives a date in January 1970.

How do I convert a date to a unix timestamp in JavaScript?

Use Date.parse with an ISO date, then divide by 1000: Math.floor(Date.parse('2024-05-11T12:18:32Z') / 1000) gives 1715429912. The Z at the end means UTC, and without it the string is read in the browser's local time zone, which gives a different timestamp in Karachi than in London. Always include the designator when the timestamp will be stored or shared.

Why does JavaScript use milliseconds instead of seconds?

The Date object was designed for millisecond precision, because browsers animate, measure and schedule in milliseconds. That is why Date.now() returns 13 digits while Python time.time() and PHP time() return 10. It is the single most common timestamp bug in JavaScript: a seconds value passed to new Date lands in 1970, and a millisecond value sent to an API that expects seconds lands tens of thousands of years ahead.

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

Nothing in value: both return the current time in milliseconds since the epoch. Date.now() is a static call that returns the number directly, while new Date().getTime() builds a Date object first and then reads the same number from it. Date.now() is faster and clearer, and it is the one to use when you only need the number. Use new Date() when you need the object for formatting.

How do I format a unix timestamp for a time zone in JavaScript?

Use toLocaleString with the timeZone option: new Date(1715429912 * 1000).toLocaleString('en-GB', { timeZone: 'Asia/Karachi' }) gives 11/05/2024, 17:18:32. The browser's time zone database handles daylight saving for you, so you never subtract offsets by hand. For a fixed format, use Intl.DateTimeFormat with the same option instead.

Does JavaScript handle the year 2038 problem?

Yes, in practice. JavaScript numbers are 64 bit floating point, so Date can represent times far beyond 2038, up to about the year 275760. The 32 bit limit only bites when a timestamp is stored in a 32 bit integer, in a database column or a binary format, or when it is sent to a system that stores it that way. The number 2147483647, the largest 32 bit timestamp, is 19 January 2038 at 03:14:07 UTC.

How do I check if a unix timestamp is expired in JavaScript?

Compare it with the current Unix time in seconds: Math.floor(Date.now() / 1000) > exp means the token or session is expired. That is the same check the JWT decoder on this site does for the exp claim. Make sure both sides are in seconds: comparing Date.now() in milliseconds with an exp in seconds makes everything look expired, because the millisecond value is a thousand times larger.

Related tools

Source: MDN Web Docs, Date. Reference values on this page were run in Node.js and checked on 27 November 2026.