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.
🌐
Google
googleapis.dev › nodejs › firestore › 3.3.3 › timestamp.js.html
timestamp.js - Documentation
* * @example * let documentRef = firestore.doc('col/doc'); * * documentRef.get().then(snap => { * let updated = snap.updateTime; * console.log(`Updated at ${updated.seconds}s ${updated.nanoseconds}ns`); * }); * * @type {number} */ get nanoseconds() { return this._nanoseconds; } /** * Returns a new `Date` corresponding to this timestamp. This may lose * precision. * * @example * let documentRef = firestore.doc('col/doc'); * * documentRef.get().then(snap => { * console.log(`Document updated at: ${snap.updateTime.toDate()}`); * }); * * @return {Date} JavaScript `Date` object representing the same point in time * as this `Timestamp`, with millisecond precision.
🌐
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.
🌐
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.
🌐
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.
Find elsewhere
🌐
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.
🌐
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 - Below is the timestamp function we will examine. It takes a Date object called myDate for its parameter and ultimately uses it to create a string in standard… ... New JavaScript and Web Development content every day.
🌐
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.
🌐
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.
🌐
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.)
🌐
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.
🌐
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 - Unfortunately, there's a small ... A Unix timestamp is defined as the number of seconds that have elapsed since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970....
🌐
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.
🌐
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 ·