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 › now
Date.now() - JavaScript | MDN
You can use Date.now() to get the current time in milliseconds, then subtract a previous time to find out how much time elapsed between the two calls.
Discussions

What is the method to obtain a current timestamp in JavaScript?
I am looking for a way to retrieve a single numerical value that indicates the current date and time, similar to a Unix timestamp. More on community.latenode.com
🌐 community.latenode.com
0
January 21, 2025
How to group timestamps every 20 minutes
_.groupBy(myArray, item => item.time / (20 * 60 * 1000)); Something like that should group by package of 20 minutes. But the format of the key is kind of ugly. You could use mapKeys in order to transform them into something more... readable :p const precision = 20 * 60 * 1000 _.mapKeys( _.groupBy(myArray, item => item.time / precision), item => moment(item * precision).format(THE_FORMAT_YOU_WANT) ) More on reddit.com
🌐 r/javascript
8
2
February 5, 2018
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 1, 2018
YouTube time stamp Shortcut
Thank you for sharing! More on reddit.com
🌐 r/shortcuts
12
20
May 2, 2021
🌐
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 in JavaScript - the fastest and most reliable method for milliseconds since Unix epoch.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-get-the-timestamp-in-javascript
How to Get the Timestamp in JavaScript? - GeeksforGeeks
July 23, 2025 - Example: Timestamp will hold the current timestamp in milliseconds, and it will be logged to the console. If you want the timestamp in seconds, you can divide the result by 1000: JavaScript · const timestamp = Date.now(); console.log(timestamp); ...
🌐
W3Schools
w3schools.com › js › js_date_methods.asp
JavaScript Date Methods
In JavaScript, date objects are created with new Date(). new Date() returns a date object with the current date and time.
🌐
ui.dev
ui.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().
Find elsewhere
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date
Date - JavaScript | MDN
For example, the timestamp 0 represents a unique instant in history, but it can be interpreted in two ways: As a UTC time, it is midnight at the beginning of January 1, 1970, UTC, As a local time in New York (UTC-5), it is 19:00:00 on December 31, 1969. The getTimezoneOffset() method returns the difference between UTC and the local time in minutes. Note that the timezone offset does not only depend on the current ...
🌐
Educative
educative.io › answers › how-to-get-the-timestamp-in-javascript
How to get the timestamp in JavaScript
Haven’t found what you were looking for? Contact Us · In JavaScript, we can check the current timestamp by using Date.now(), which returns the current timestamp in milliseconds since January 1, 1970 (UTC).
🌐
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().
🌐
Toptal
toptal.com › developers › software › definitive-guide-to-datetime-manipulation
How to get the Timestamp And Date in Javascript: JS DateTime | Toptal®
December 2, 2020 - If you instead want to get the current timestamp in JavaScript, you can create a new Date object and use the getTime() method.
🌐
Sentry
sentry.io › sentry answers › javascript › how do i get the current date in javascript?
How do I get the Current Date in JavaScript? | Sentry
December 15, 2022 - You can also create a new Date object, which represents a single moment in time, and save the date as a UTC timezone timestamp: ... const currentTime = new Date(); console.log(currentTime.toUTCString()); // Mon, 28 Nov 2022 11:24:21 GMT
🌐
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.)
🌐
Toptal
toptal.com › software › definitive-guide-to-datetime-manipulation
How to get the Timestamp And Date in Javascript
December 2, 2020 - If you instead want to get the current timestamp in JavaScript, you can create a new Date object and use the getTime() method.
🌐
Codemia
codemia.io › knowledge-hub › path › How-do-I-get-a-timestamp-in-JavaScript
How do I get a timestamp in JavaScript?
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises
🌐
Medium
medium.com › @python-javascript-php-html-css › how-to-get-timestamps-in-javascript-a-guide-d5c2343afa32
How to Get Timestamps in JavaScript: A Guide
September 25, 2024 - The frontend script demonstrates how to get a timestamp in JavaScript using two methods. The first method uses the Date.now() function, which returns the current timestamp in milliseconds since January 1, 1970. This is a straightforward way ...
🌐
InfluxData
influxdata.com › home › how to get, convert & format javascript date from timestamp | influxdata
How to Get, Convert & Format JavaScript Date From Timestamp | InfluxData
February 10, 2023 - To get the current timestamp, we can create a new Date object and call the getTime() method, which returns the number of milliseconds since January 1, 1970, 00:00:00 Universal Coordinated Time (UTC).
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-date-now-method
JavaScript Date now() Method
July 11, 2025 - The code snippet utilizes `Date.now()` to retrieve the current timestamp in milliseconds since the Unix epoch.
🌐
Latenode
community.latenode.com › other questions › javascript
What is the method to obtain a current timestamp in JavaScript? - JavaScript - Latenode Official Community
January 21, 2025 - I am looking for a way to retrieve a single numerical value that indicates the current date and time, similar to a Unix timestamp.
🌐
Arunkumar Blog
arungudelli.com › home › tutorial › javascript › 4 ways to get the current timestamp in javascript
4 Ways To Get The Current Timestamp In JavaScript
November 7, 2019 - Math.floor(Date.now() / 1000) // ... readability. For cross browser compatbility we can use getTime() method of Date object to get the current timestamp in milliseconds...
🌐
TecAdmin
tecadmin.net › how-to-get-the-current-timestamp-in-javascript
How to Get the Current Timestamp in JavaScript – TecAdmin
April 26, 2025 - Retrieving the current timestamp in JavaScript is a common task that can be accomplished using the built-in Date.now() method. This method returns the number of milliseconds that have elapsed since January 1, 1970, 00:00:00 UTC, and can be used to perform various calculations and set timeouts.