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
🌐
Singsys
blog.singsys.com › home › how to get a timestamp in javascript
Calculate time in JavaScript Using TimeStamp – Singsys Blog
November 2, 2017 - Method getTime() returns the total number of milliseconds between midnight of January 1, 1970 and the date specified by you.
🌐
Sabe
sabe.io › blog › javascript-current-timestamp
How to Get the Current Timestamp in JavaScript | Sabe
September 22, 2022 - The Date object is a built-in object in JavaScript that represents a single moment in time. To get the current timestamp, we can use the now() method.
Discussions

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 2, 2018
How to Get Timestamps in JavaScript: A Guide
Understanding JavaScript Timestamps Obtaining a timestamp in JavaScript is a common requirement for developers working with dates and times. A… More on reddit.com
🌐 r/MailDevNetwork
1
June 15, 2023
How to get the signature and timestamp for this GET request?
Have a look through the network requests prior to the one with the data, perhaps the timestamp & signature is in one of those? Otherwise it could be generated client-side in which case you'll need to sift through the client-side javascript to find the code that does this, and replicate that logic in your script More on reddit.com
🌐 r/webscraping
3
2
April 15, 2023
How can I display this firebase Timestamp?
I think serverTimestamp is null immediately after creation, as it hasn't been generated yet. I'll admit I'm not super familiar with React or Firebase, but it seems to me that immediately after calling addDoc, your list of messages is rebuilt and the server timestamp on the new message hasn't had time to be generated yet, hence the null value. Maybe you could supply a fallback such as message.createdAt?.toDate()?.toDateString() || '' in your template to avoid the null error? Again, not familiar with how Firebase works, but if onSnapshot runs its callback whenever the message is updated, then it may just be a momentary flicker where the timestamp isn't displayed in the UI. As a final note, it may not be the most efficient design to rebuild the entire message list whenever a new message is added - just something to think about. More on reddit.com
🌐 r/learnjavascript
2
1
May 11, 2023
🌐
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
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date
Date - JavaScript | MDN
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.
Find elsewhere
🌐
JavaScript in Plain English
javascript.plainenglish.io › how-to-create-a-timestamp-from-a-date-object-in-javascript-760d58a3511f
How to Create a Readable Timestamp in JavaScript | by Nevin Katz | JavaScript in Plain English
August 8, 2021 - JavaScript allows you to create Date objects that store the time at which they were created and have their own unique set of methods. You can instantiate one the way you would another type of object with the new keyword. ... Suppose we want to take this Date object and extract a timestamp in the format below, with the T separating the date and time.
🌐
W3Schools
w3schools.com › jsrEF › event_timestamp.asp
timeStamp Event Property
The timeStamp event property returns the number of milliseconds from the document was finished loading until the specific event was created.
🌐
DZone
dzone.com › coding › javascript › javascript: creating timestamps with time zone offsets
JavaScript: Creating timestamps with time zone offsets
June 1, 2010 - When you call getTime method on Date object you get the number of milliseconds from Unix epoch. Although your current Date object keeps time with some offset getTime gives seconds in UTC. Keep this in mind when creating timestamps if you are not living on zero-meridian.
🌐
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.
🌐
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 ...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-return-the-current-timestamp-with-momentjs
How to Return the Current Timestamp with Moment.js? - GeeksforGeeks
July 23, 2025 - Current Milliseconds Timestamp: 1721910377892 · Comment · Article Tags: Article Tags: JavaScript · Web Technologies · Moment.js · JavaScript Basics · Introduction to JavaScript4 min read · Variables and Datatypes in JavaScript5 min read · JavaScript Operators4 min read ·
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Event › timeStamp
Event: timeStamp property - Web APIs | MDN
July 4, 2024 - The timeStamp read-only property of the Event interface returns the time (in milliseconds) at which the event was created.
🌐
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.
🌐
Codemia
codemia.io › knowledge-hub › path › convert_a_unix_timestamp_to_time_in_javascript
Convert a Unix timestamp to time in JavaScript
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises
🌐
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).
🌐
W3Schools
w3schools.com › js › js_dates.asp
JavaScript Dates
February 4, 2026 - JavaScript stores dates as number of milliseconds since January 01, 1970.
🌐
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 - JavaScript’s global Date object comes with methods to interact with dates and times. The Date.now() function returns the current timestamp in milliseconds. These milliseconds are counted from the UNIX epoch.