Timestamp in milliseconds

To get the number of milliseconds since Unix epoch, call Date.now:

Date.now()

Alternatively, use the unary operator + to call Date.prototype.valueOf:

+ new Date()

Alternatively, call valueOf directly:

new Date().valueOf()

To support IE8 and earlier (see compatibility table), create a shim for Date.now:

if (!Date.now) {
    Date.now = function() { return new Date().getTime(); }
}

Alternatively, call getTime directly:

new Date().getTime()

Timestamp in seconds

To get the number of seconds since Unix epoch, i.e. Unix timestamp:

Math.floor(Date.now() / 1000)

Alternatively, using bitwise-or to floor is slightly faster, but also less readable and may break in the future (see explanations 1, 2):

Date.now() / 1000 | 0

Timestamp in milliseconds (higher resolution)

Use performance.now:

var isPerformanceSupported = (
    window.performance &&
    window.performance.now &&
    window.performance.timing &&
    window.performance.timing.navigationStart
);

var timeStampInMs = (
    isPerformanceSupported ?
    window.performance.now() +
    window.performance.timing.navigationStart :
    Date.now()
);

console.log(timeStampInMs, Date.now());

Answer from daveb on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date
Date - JavaScript - MDN Web Docs - Mozilla
A JavaScript date is fundamentally specified as the time in milliseconds that has elapsed since the epoch, which is defined as the midnight at the beginning of January 1, 1970, UTC (equivalent to the UNIX epoch).
Discussions

date - Convert a Unix timestamp to time in JavaScript - Stack Overflow
I am storing time in a MySQL database as a Unix timestamp and that gets sent to some JavaScript code. How would I get just the time out of it? For example, in HH/MM/SS format. More on stackoverflow.com
🌐 stackoverflow.com
javascript - Convert normal date to unix timestamp - Stack Overflow
How can I convert normal date 2012.08.10 to unix timestamp in javascript? Fiddle: http://jsfiddle.net/J2pWj/ I've seen many posts here that convert it in PHP, Ruby, etc... But I need to do this in... More on stackoverflow.com
🌐 stackoverflow.com
Date and time in JavaScript
There was a lot less cursing in that article than I expected. More on reddit.com
🌐 r/javascript
30
67
January 4, 2018
Congratulations to Unix time for celebrating 1,500,000,000* tonight!

When programmers are obsessing over base 10 patterns you realise standards are dropping.

More on reddit.com
🌐 r/javascript
20
171
July 14, 2017
🌐
Sentry
sentry.io › sentry answers › javascript › convert unix timestamp to date and time in javascript
Convert Unix timestamp to date and time in JavaScript | Sentry
To convert these into human-readable dates and times, we can use JavaScript’s Date object. This object’s constructor takes a value similar to a Unix timestamp, but in milliseconds rather than seconds.
🌐
Coderwall
coderwall.com › p › rbfl6g › how-to-get-the-correct-unix-timestamp-from-any-date-in-javascript
How to get the correct Unix Timestamp from any Date in JavaScript (Example)
June 26, 2023 - // Copy & Paste this Date.prototype.getUnixTime = function() { return this.getTime()/1000|0 }; if(!Date.now) Date.now = function() { return new Date(); } Date.time = function() { return Date.now().getUnixTime(); } // Get the current time as ...
🌐
Fireship
fireship.dev › get-current-timestamp-javascript
How to get the current timestamp in JavaScript
The UNIX timestamp is defined as the number of seconds since January 1, 1970 UTC. In JavaScript, in order to get the current timestamp, you can use Date.now().
🌐
Futurestud.io
futurestud.io › tutorials › how-to-get-a-unix-timestamp-in-javascript-or-node-js
How to Get a UNIX Timestamp in JavaScript or Node.js
June 23, 2022 - /** * Returns the UNIX timestamp for the given `date`. Defaults to `Date.now()` * when not providing the `date` argument to the method call. * * @returns {Number} */ function unixTimestamp (date = Date.now()) { return Math.floor(date / 1000) } That’s it! Enjoy using UNIX timestamps in JavaScript!
🌐
Medium
medium.com › @python-javascript-php-html-css › a-guide-to-obtaining-a-timestamp-in-javascript-04a81f4e5b9c
A Guide to Obtaining a Timestamp in JavaScript
September 22, 2024 - The client-side script uses Date.now() to get the current timestamp in milliseconds since the Unix epoch (January 1, 1970). This value is then converted to seconds by dividing by 1000 and rounding down using Math.floor().
Find elsewhere
🌐
Day.js
day.js.org › docs › en › display › unix-timestamp
Unix Timestamp · Day.js
dayjs('2019-01-25').unix() // 1548381600 (Returns Unix timestamp based on local timezone.)
🌐
Epoch Converter
epochconverter.com
Epoch Converter - Unix Timestamp Converter
The first line for each language shows how to get the current epoch time. The second line shows how to convert an epoch timestamp to a human-readable date. Replace the example epoch time 1800000000 with your own value.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › now
Date.now() - JavaScript - MDN Web Docs - Mozilla
// This example takes 2 seconds to run const start = Date.now(); console.log("starting timer..."); // Expected output: "starting timer..." setTimeout(() => { const ms = Date.now() - start; console.log(`seconds elapsed = ${Math.floor(ms / 1000)}`); // Expected output: "seconds elapsed = 2" }, 2000);
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-convert-unix-timestamp-to-time-in-javascript
How to convert Unix timestamp to time in JavaScript ? - GeeksforGeeks
July 12, 2025 - The Intl.DateTimeFormat object allows for formatting dates and times according to locale-specific conventions. This method provides a flexible and powerful way to format the time extracted from a UNIX timestamp.
🌐
Moment.js
momentjs.com › docs
Moment.js | Docs
Display Format Time from now Time from X Time to now Time to X Calendar Time Difference Unix Timestamp (milliseconds) Unix Timestamp (seconds) Days in Month As Javascript Date As Array As JSON As ISO 8601 String As Object As String Inspect
🌐
Zipy
zipy.ai › blog › convert-unix-timestamp-to-date-and-time-in-javascript
convert unix timestamp to date and time in javascript
April 12, 2024 - To convert a Unix timestamp to a date and time, you can use the Date constructor, passing the timestamp multiplied by 1000 (to convert seconds to milliseconds, as JavaScript deals with time in milliseconds).
🌐
Unix Time Stamp
unixtimestamp.com
Unix Time Stamp - Epoch Converter
CSS Formatter GO Formatter HTML Beautifier & Formatter Javascript Formatter Javascript Obfuscate JSON Formatter & Beautifier JSON Editor JSON Validator Perl Formatter PHP Formatter Python Formatter Ruby Formatter SQL Formatter XML Formatter & Beautifier ... Supports Unix timestamps in seconds, milliseconds, microseconds and nanoseconds.
🌐
Day.js
day.js.org › docs › en › parse › unix-timestamp
Unix Timestamp (seconds) · Day.js
Create a Day.js object from a Unix timestamp (10 digits, seconds since the Unix Epoch).
🌐
Nesin
nesin.io › blog › javascript-date-to-unix-timestamp
How to convert Date to Unix Timestamp in Javascript - Nesin.io
April 2, 2023 - In Javascript, Date object has getTime() method and it returns number of milliseconds since the Unix epoch which is January 1, 1970 00:00:00 UTC · And unix timestamp are mostly represented in seconds not milliseconds and so we'll be converting ...
🌐
CoreUI
coreui.io › answers › how-to-get-current-timestamp-in-javascript
How to get current timestamp in JavaScript · CoreUI
September 30, 2025 - Use Date.now() to get the current timestamp as milliseconds since Unix epoch.