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
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-convert-a-date-string-to-timestamp-in-javascript
How to Convert a Date String to Timestamp in JavaScript ? - GeeksforGeeks
July 23, 2025 - In this approach, using new Date() creates a date object from a string, then .getTime() extracts the Unix timestamp (milliseconds since 1970). ... Example: In this example, the date string "2023-08-23T12:34:56" is first converted into a Date ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › parse
Date.parse() - JavaScript | MDN
The Date.parse() static method parses a string representation of a date, and returns the date's timestamp. // Standard date-time string format const unixTimeZero = Date.parse("1970-01-01T00:00:00Z"); // Non-standard format resembling toUTCString() const javaScriptRelease = Date.parse("04 Dec ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date
Date - JavaScript | MDN
Returns a new Temporal.Instant object with the same epochMilliseconds value as this date's timestamp. ... Returns the "time" portion of the Date as a human-readable string. ... Converts a date to a string using the UTC timezone. ... Returns the primitive value of a Date object. Overrides the Object.prototype.valueOf() method. ... Converts this Date object to a primitive value. The following examples show several ways to create JavaScript dates:
🌐
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 - We can pass in options to format the string in different ways. const timestamp = 1616608200000; // example timestamp const date = new Date(timestamp); const formattedDate = date.toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', ...
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Date and time
The call to Date.parse(str) parses the string in the given format and returns the timestamp (number of milliseconds from 1 Jan 1970 UTC+0). If the format is invalid, returns NaN. ... Date and time in JavaScript are represented with the Date object.
🌐
Stack Abuse
stackabuse.com › bytes › how-to-convert-a-date-to-timestamp-in-javascript
How to Convert a Date to Timestamp in JavaScript
October 4, 2023 - It'll be a similar process as before, but with the extra step of converting the string to a Date object and then the timestamp. Just make sure your date string is in a format that the Date constructor can understand. According to MDN: The JavaScript specification only specifies one format to ...
Find elsewhere
🌐
Plain English
plainenglish.io › home › blog › javascript › how to convert a date string to timestamp in javascript?
How to Convert a Date String to Timestamp in JavaScript?
April 19, 2022 - In this article, we'll look at ways to convert a date to a timestamp in JavaScript. We can use the Date.parse() method to convert the date string into a timestamp.
🌐
W3Schools
w3schools.com › jsref › jsref_tostring_date.asp
JavaScript Date toString() Method
The toString() method returns a date object as a string. Every JavaScript object has a toString() method.
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-convert-date-to-timestamp
Convert a Date or Date String to Timestamp in JavaScript | bobbyhadz
If you get an invalid Date when creating the Date object, you need to format the string correctly before passing it to the Date() constructor (more on that below). The getTime() method returns the number of milliseconds since the Unix Epoch (1st of January, 1970 00:00:00). If you need to convert the result to seconds, divide it by 1000. ... Copied!const str = '2022-04-26'; const date = new Date(str); // ✅ If you need to convert to Seconds const timestampSeconds = Math.floor(date.getTime() / 1000); console.log(timestampSeconds); // 👉️ 1650931200
🌐
Timestamp Converter
timestamp.online › article › how-to-convert-timestamp-to-datetime-in-javascript
How To Convert Timestamp To Date and Time in JavaScript - Code Example
Converts a Date object to a string, according to universal time · You can learn more about toDateString in documentation. var ts = new Date(1768200518000); console.log(ts.toDateString()); # Mon Jan 12 2026 · You can learn more about toISOString in documentation. var ts = new Date(1768200518 * 1000); console.log(ts.toISOString()); # 26-01-12T07:48:38+01:00 · var ts = new Date(1768200518000); JavaScript · Convert timestamp to datetime ·
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › Date
Date() constructor - JavaScript | MDN
An integer value representing the timestamp (the number of milliseconds since midnight at the beginning of January 1, 1970, UTC — a.k.a. the epoch). ... A string value representing a date, parsed and interpreted using the same algorithm implemented by Date.parse().
🌐
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 - You can use the toISOString() method to convert a date object to a string in ISO 8601 format. ... Create a date object with new Date(‘YYYY-MM-DD’) and then use getTime() to get the timestamp.
🌐
Tutorial Republic
tutorialrepublic.com › faq › how-to-generate-a-timestamp-in-javascript.php
How to Generate a Timestamp in JavaScript
<script> // Creating a timestamp var timestamp = Date.now(); console.log(timestamp); // Converting it back to human-readable date and time var d = new Date(timestamp); console.log(d); </script> The Date.now() method is supported in all major ...
🌐
Moment.js
momentjs.com › docs
Moment.js | Docs
Display Format Time from now Time from X Time to now Time to X Calendar Time Difference Unix Timestamp (milliseconds) Unix Timestamp (seconds) Days in Month As Javascript Date As Array As JSON As ISO 8601 String As Object As String Inspect
🌐
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.
🌐
Zipy
zipy.ai › blog › convert-unix-timestamp-to-date-and-time-in-javascript
convert unix timestamp to date and time in javascript
April 12, 2024 - The Date object in JavaScript is your go-to for handling dates and times. To convert a Unix timestamp to a date and time, you can use the Date constructor, passing the timestamp multiplied by 1000 (to convert seconds to milliseconds, as JavaScript deals with time in milliseconds).