How to Get the Current Unix Time in JavaScript
Math.floor(Date.now() / 1000) is the current Unix time in seconds in JavaScript: the number of seconds since the start of 1 January 1970, UTC. Date.now() on its own counts milliseconds, so it's 1000 times larger.
Syntax
const <seconds> = Math.floor(Date.now() / 1000);
| Part | What it does |
|---|---|
Date.now() | Returns the current time as the number of milliseconds since 1 January 1970, UTC. |
/ 1000 | Turns milliseconds into seconds, with a fraction left over. |
Math.floor(...) | Drops the fraction by rounding down, which gives whole seconds. |
<seconds> | The variable that holds the Unix time. |
MDN describes Date.now(): it "returns the number of milliseconds elapsed since the epoch, which is defined as the midnight at the beginning of January 1, 1970, UTC." And Math.floor() "always rounds down and returns the largest integer less than or equal to a given number."
The Example
The example prints the current time in milliseconds and in seconds, then turns the seconds back into a date with new Date(seconds * 1000) and prints it in ISO 8601 format, to check that the number really is now.
Prerequisites
- Node.js. This guide uses Node.js 26.13.1.
Step 1: Write the Code
Create a file named main.js:

const milliseconds = Date.now();
const seconds = Math.floor(milliseconds / 1000);
console.log(milliseconds);
console.log(seconds);
console.log(new Date(seconds * 1000).toISOString());
Step 2: Run It
node main.js
1796059333363
1796059333
2026-11-30T17:22:13.000Z

The command is the same in zsh, bash and PowerShell. Your numbers will be later, because they're the time you run it.
What Happened
Date.now()printed 13 digits: the milliseconds since 1970.- The seconds have 10 digits. Dividing by 1000 moved the decimal point three places, and
Math.floordropped the fraction, here.363of a second. - The date shows the same moment in UTC.
new Date()takes milliseconds, so the seconds are multiplied by 1000 again, and toISOString() always writes UTC: "The timezone is always UTC, as denoted by the suffix Z." The milliseconds are.000because the fraction was rounded away.
Seconds are what most other systems expect. A JSON Web Token's exp, nbf and iat claims, for example, are Unix times in seconds, and so are the timestamps of most other languages and of the date +%s command.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Using Date.now() where seconds are expected | The value is 1000 times too large, so a time 15 minutes away looks tens of thousands of years away | Divide by 1000 and round down |
Rounding with Math.round | When the fraction is .5 or more, it rounds up to a second that hasn't happened yet | Use Math.floor |
Passing seconds to new Date() | new Date() reads milliseconds, so the date lands in January 1970 | Multiply the seconds by 1000 first |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| A date in 1970 | Seconds were passed where milliseconds are expected | Multiply by 1000 |
| A year far in the future | Milliseconds were used where seconds are expected | Divide by 1000 and round down |
FAQ
Is Date.now() in UTC?
It counts from midnight UTC on 1 January 1970, so the number is the same everywhere in the world at the same moment. Time zones only matter when you turn it into a date you read, and toISOString() always shows UTC.
Why Math.floor and not Math.trunc?
For a time after 1970 the result is the same, because the number is positive. Math.floor rounds down, which is the usual way to count whole seconds that have passed.
Conclusion
Math.floor(Date.now() / 1000) gives the current Unix time in seconds. Keep Date.now() for milliseconds, and convert whenever another system expects seconds.
Additional Resources
- Date.now(), Math.floor() and Date.prototype.toISOString(), on MDN.
