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.
🌐
Mirth Community
forums.mirthproject.io › home › mirth connect › support
Getting the current Datetime in javascript - Mirth Community
February 7, 2011 - //Gets the current Date Time in the format yyyyMMddHHmmss function GetCurrentHL7DateTime() { var dateFormat = new Packages.java.text.SimpleDateFormat("yyyyMMddHHmmss"); var dateNow = new Packages.java.util.Date(); return dateFormat.format(dateNow).toString() + ""; } output: 20110207081647 As you can see I'm actually calling Java functions to do the job. Also I put + "" behind the return value this is to transform the java.lang.string to an javascript string.
Discussions

Timestamp to current date and time?
Hi all… what would the code be that goes into a function node to take a timestamp and output the date and time in the normal date and time format? More on discourse.nodered.org
🌐 discourse.nodered.org
0
0
June 17, 2018
How can I get the current timestamp in JavaScript? - Ask a Question - TestMu AI Community
I’m looking for a simple way to get the current date and time as a single number in JavaScript, similar to a Unix timestamp (i.e., the number of seconds or milliseconds since January 1, 1970). What’s the best method to generate a JavaScript timestamp like this? More on community.testmuai.com
🌐 community.testmuai.com
0
July 18, 2025
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
0
January 21, 2025
How to use JavaScript to Get Timestamps Explained with Examples - Guide - The freeCodeCamp Forum
You can use Date.now() to get the current timestamp in milliseconds. You can easily convert the timestamp to seconds like this: Math.floor(Date.now() / 1000) If your browser does not support Date.now() , you can use new Date().getTime() to get the timestamp in milliseconds. More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
2
June 24, 2019
🌐
QuickRef.ME
quickref.me › home › how to get the current timestamp in seconds in javascript - quickref.me
How to get the current timestamp in seconds in JavaScript - QuickRef.ME
In this Article we will go through how to get the current timestamp in seconds only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.
🌐
W3Schools
w3schools.com › js › js_date_methods.asp
JavaScript Get Date Methods
In JavaScript, date objects are created with new Date(). new Date() returns a date object with the current date and time. ... The get methods above return Local time.
🌐
Node-RED
discourse.nodered.org › general
Timestamp to current date and time? - General - Node-RED Forum
June 17, 2018 - Hi all… what would the code be that goes into a function node to take a timestamp and output the date and time in the normal date and time format?
Find elsewhere
🌐
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.
🌐
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 ...
🌐
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 then convert the timestamp to a date and format it as needed: const dateToShow = new Date(currentTime); console.log(dateToShow.toString()); // Mon Nov 28 2022 13:24:21 GMT+0200 (South Africa Standard Time) You can format the date using one of the various formatting methods on the Date object, such as .toString(), as described in our answer to the following question: How do I Format a Date in JavaScript?.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-get-the-timestamp-in-javascript
How to Get the Timestamp in JavaScript? - GeeksforGeeks
July 23, 2025 - Example: The new Date().getTime() method is used to create a new Date object and retrieve its timestamp in milliseconds. The timestamp variable will hold the current timestamp, and it will be logged to the console.
🌐
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().
🌐
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 - ... // Get the current timestamp in milliseconds since epoch const timestamp = Date.now(); console.log(timestamp); // Get the current timestamp in seconds since epoch const unixTimestamp = Math.floor(Date.now() / 1000); console.log(unixTimestamp); ...
🌐
TestMu AI Community
community.testmuai.com › ask a question
How can I get the current timestamp in JavaScript? - Ask a Question - TestMu AI Community
July 18, 2025 - I’m looking for a simple way to get the current date and time as a single number in JavaScript, similar to a Unix timestamp (i.e., the number of seconds or milliseconds since January 1, 1970). What’s the best method to …
🌐
Bugfender
bugfender.com › blog › javascript-date-and-time
The Definitive Guide to JavaScript Date and Time | Bugfender
February 18, 2025 - We know that the Date constructor can create a Date object by passing the timestamp milliseconds as an argument. Hence, we can pass the Date.now() to the Date constructor to get the current date and time.
🌐
Toptal
toptal.com › developers › software › definitive-guide-to-datetime-manipulation
How to get the Timestamp And Date in Javascript: JS DateTime | Toptal®
January 16, 2026 - If you instead want to get the current timestamp in JavaScript, you can create a new Date object and use the getTime() method.
🌐
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.
🌐
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).
🌐
Educative
educative.io › answers › how-to-get-the-timestamp-in-javascript
How to get the timestamp in JavaScript
Getting the timestamp in JavaScript is a fundamental task that can help us manage time effectively in our applications. Whether we use Date.now(), the Date object, or + operator, these methods allow us to retrieve the current timestamp in milliseconds or seconds.
🌐
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
🌐
freeCodeCamp
forum.freecodecamp.org › guide
How to use JavaScript to Get Timestamps Explained with Examples - Guide - The freeCodeCamp Forum
June 24, 2019 - You can use Date.now() to get the current timestamp in milliseconds. You can easily convert the timestamp to seconds like this: Math.floor(Date.now() / 1000) If your browser does not support Date.now() , you can use new Date().getTime() to get ...