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
🌐
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 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). This timestamp is timezone-agnostic and uniquely defines an instant in history.
🌐
n8n
community.n8n.io › feature requests
Add Unix Timestamp and Javascript Timestamp converstions to the date/time app - Feature Requests - n8n Community
January 10, 2024 - The idea is: The Date and Time app has 7 actions. I suggest adding two to easily convert Unix and Javascript timestamps. My use case: I’m exporting Zillow API data and all the listing date/times and change date/times are in Unix Time Stamp (aka milliseconds) Example: listingDateTimeOnZillow: 1699724220000.
🌐
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 ...
Find elsewhere
🌐
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 - By importing the library with require(‘moment’), we can utilize its methods to fetch the current Unix timestamp directly using moment().unix(). This approach is beneficial for back-end operations where consistent time formatting and manipulation are required. Both scripts log the timestamp to the console using console.log(), showcasing how these methods can be employed in different JavaScript environments.
🌐
Career Karma
careerkarma.com › blog › javascript › javascript timestamp: a step-by-step guide
JavaScript Timestamp: A Step-By-Step Guide | Career Karma
December 1, 2023 - To get a JavaScript timestamp format can be achieved using the Date() object, which holds the current time in a readable timestamp format.
🌐
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); Output · 1730311218300 ·
🌐
freeCodeCamp
freecodecamp.org › news › javascript-timestamp-how-to-use-gettime-to-generate-timestamps-in-js
JavaScript Timestamp – How to Use getTime() to Generate Timestamps in JS
August 19, 2022 - And there are different methods for generating such timestamps. When we make use of the different JavaScript methods for generating timestamps, they return the number of milliseconds that has passed since 1 January 1970 UTC (the Unix 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().
🌐
W3Schools
w3schools.com › jsref › jsref_gettime.asp
JavaScript Date getTime() Method
altKey (Mouse) altKey (Key) animationName bubbles button buttons cancelable charCode clientX clientY code ctrlKey (Mouse) ctrlKey (Key) currentTarget data defaultPrevented deltaX deltaY deltaZ deltaMode detail elapsedTime elapsedTime eventPhase inputType isTrusted key keyCode location metaKey (Mouse) metaKey (Key) newURL oldURL offsetX offsetY pageX pageY persisted propertyName relatedTarget relatedTarget screenX screenY shiftKey (Mouse) shiftKey (Key) target targetTouches timeStamp touches type which (Mouse) which (Key) view HTML Event Methods
🌐
Go Make Things
gomakethings.com › how-to-create-and-work-with-timestamps-in-vanilla-js
How to create and work with timestamps in vanilla JS | Go Make Things
September 21, 2020 - A timestamp is a number used to represent a fixed point in a time. Unlike date strings, which are relative to a specific timezone or location, a timestamp is absolute, and represents the same moment regardless of where a person lives.
🌐
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).
🌐
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 - If you’re working with timestamps from an external source, they may be in Unix timestamp format, representing the number of seconds since January 1, 1970, 00:00:00 UTC. To convert a Unix timestamp to a JavaScript timestamp, we can multiply it by 1,000 to convert it to milliseconds.
🌐
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.