const timestamp = new Date().getTime()

console.log(timestamp)

For more information, see @James McMahon's answer.

Answer from ExpExc on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › UTC
Date.UTC() - JavaScript - MDN Web Docs
The Date.UTC() static method accepts parameters representing the date and time components similar to the Date constructor, but treats them as UTC. It returns the number of milliseconds since January 1, 1970, 00:00:00 UTC.
Discussions

timezone - How do I get a UTC Timestamp in JavaScript? - Stack Overflow
While writing a web application, it makes sense to store (server side) all datetimes in the DB as UTC timestamps. I was astonished when I noticed that you couldn't natively do much in terms of Tim... More on stackoverflow.com
🌐 stackoverflow.com
javascript - How to convert a Date to UTC? - Stack Overflow
The getTimezoneOffset() method returns the time zone difference, in minutes, from current locale (host system settings) to UTC. ... This means that the offset is positive if the local timezone is behind UTC, and negative if it is ahead. For example, for time zone UTC+02:00, -120 will be returned. let d = new Date... More on stackoverflow.com
🌐 stackoverflow.com
How to REALLY get a UTC Date object

var date = new Date('2015-10-11T14:03:19.243Z'); var str = date.toISOString();

More on reddit.com
🌐 r/javascript
6
1
February 4, 2014
Date as string, in UTC (no signifier), convert to local time
(get-date "2021-08-26 16:44:42").ToLocalTime() More on reddit.com
🌐 r/PowerShell
7
2
April 9, 2021
🌐
Attacomsian
attacomsian.com › blog › javascript-get-current-date-time-in-utc
How to get current date and time in UTC using JavaScript
September 12, 2022 - const date = new Date() // UTC day of the month (1-31) console.log(date.getUTCDate()) // 11 // UTC month (0-11) console.log(date.getUTCMonth()) // 8 (September) // UTC year of the date console.log(date.getUTCFullYear()) // 2022 // UTC hour of the date console.log(date.getUTCHours()) // 18 // UTC minutes of the date console.log(date.getUTCMinutes()) // 32 // UTC seconds of the date console.log(date.getUTCSeconds()) // 45 // UTC milliseconds of the date console.log(date.getUTCMilliseconds()) // 897
🌐
W3Schools
w3schools.com › jsref › jsref_getutcdate.asp
JavaScript Date getUTCDate() Method
new Date() constructor getDate() getDay() getFullYear() getHours() getMilliseconds() getMinutes() getMonth() getSeconds() getTime() getTimezoneOffset() getUTCDate() getUTCDay() getUTCFullYear() getUTCHours() getUTCMilliseconds() getUTCMinutes() getUTCMonth() getUTCSeconds() now() parse() prototype setDate() setFullYear() setHours() setMilliseconds() setMinutes() setMonth() setSeconds() setTime() setUTCDate() setUTCFullYear() setUTCHours() setUTCMilliseconds() setUTCMinutes() setUTCMonth() setUTCSeconds() toDateString() toISOString() toJSON() toLocaleDateString() toLocaleTimeString() toLocaleString() toString() toTimeString() toUTCString() UTC() valueOf() JS Function
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-get-javascript-date-in-utc-using-momentjs
How to get JavaScript Date in UTC using MomentJS? - GeeksforGeeks
July 23, 2025 - The moment().utc() method returns a Moment object representing the current date and time in UTC. Example: In this example we are using the moment().utc() method to get the current date and time in UTC.
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-get-current-date-and-time-in-utc
Get the current Date and Time in UTC/GMT using JavaScript | bobbyhadz
January 15, 2022 - UTC and GMT don't change for Daylight Saving Time (DST) and always share the same current time. In the second example, we used the toUTCString method to get the GMT/UTC representation of the date.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › toUTCString
Date.prototype.toUTCString() - JavaScript - MDN Web Docs
July 10, 2025 - The toUTCString() method of Date instances returns a string representing this date in the RFC 7231 format, with negative years allowed. The timezone is always UTC. toGMTString() is an alias of this method.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › now
Date.now() - JavaScript - MDN Web Docs - Mozilla
The Date.now() static method returns the number of milliseconds elapsed since the epoch, which is defined as the midnight at the beginning of January 1, 1970, UTC. // This example takes 2 seconds to run const start = Date.now(); console.log("starting timer..."); // Expected output: "starting ...
Find elsewhere
🌐
Medium
frontendinterviewquestions.medium.com › how-to-get-current-time-in-javascript-a7cdb04cd220
How to Get Current Time in JavaScript | by Pravin M | Medium
June 19, 2024 - // Create a new Date object let currentDateUTC = new Date(); // Get current UTC time let currentUTCTime = currentDateUTC.toUTCString(); console.log("Current UTC time is:", currentUTCTime);
Top answer
1 of 16
221
  1. Dates constructed that way use the local timezone, making the constructed date incorrect. To set the timezone of a certain date object is to construct it from a date string that includes the timezone. (I had problems getting that to work in an older Android browser.)

  2. Note that getTime() returns milliseconds, not plain seconds.

For a UTC/Unix timestamp, the following should suffice:

Math.floor((new Date()).getTime() / 1000)

It will factor the current timezone offset into the result. For a string representation, David Ellis' answer works.

To clarify:

new Date(Y, M, D, h, m, s)

That input is treated as local time. If UTC time is passed in, the results will differ. Observe (I'm in GMT +02:00 right now, and it's 07:50):

> var d1 = new Date();
> d1.toUTCString();
"Sun, 18 Mar 2012 05:50:34 GMT" // two hours less than my local time
> Math.floor(d1.getTime()/ 1000)
1332049834 

> var d2 = new Date( d1.getUTCFullYear(), d1.getUTCMonth(), d1.getUTCDate(), d1.getUTCHours(), d1.getUTCMinutes(), d1.getUTCSeconds() );
> d2.toUTCString();
"Sun, 18 Mar 2012 03:50:34 GMT" // four hours less than my local time, and two hours less than the original time - because my GMT+2 input was interpreted as GMT+0!
> Math.floor(d2.getTime()/ 1000)
1332042634

Also note that getUTCDate() cannot be substituted for getUTCDay(). This is because getUTCDate() returns the day of the month; whereas, getUTCDay() returns the day of the week.

2 of 16
153

The easiest way of getting UTC time in a conventional format is as follows:

> new Date().toISOString()
"2016-06-03T23:15:33.008Z"

if you need EPOC timestamp, pass your date to Date.parse method

> Date.parse(new Date)
1641241000000
> Date.parse('2022-01-03T20:18:05.833Z')
1641241085833

Or you can use + for type casting from Date to Int

> +new Date 
1641921156671

EPOC timestamp in seconds.

> parseInt(Date.parse('2022-01-03T20:18:05.833Z') / 1000)
1641241085
> parseInt(new Date / 1000)
1643302523
🌐
GeeksforGeeks
geeksforgeeks.org › javascript-date-utc-method
JavaScript Date UTC() Method | GeeksforGeeks
July 12, 2024 - The code creates a UTC date object representing February 28, 2010, and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC. The value is then logged to the console. ... JavaScript Date constructor is used to create a new Date object. The value returned will be different on the basis of whether the object is called with or without the new keyword. If we call the object new keyword a Date object is created otherwise a string representing the current dat-time is retur
🌐
W3Schools
w3schools.com › JSREF › jsref_utc.asp
JavaScript Date UTC() Method
Create a date object using UTC time instead of local time: let d = new Date(Date.UTC(2020, 02, 30)); Try it Yourself » · JavaScript Dates · JavaScript Date Formats · JavaScript Date Get Methods · JavaScript Date Set Methods · ❮ Previous ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › getUTCDate
Date.prototype.getUTCDate() - JavaScript - MDN - Mozilla
July 10, 2025 - const date1 = new Date("August 19, 1975 23:15:30 GMT+11:00"); const date2 = new Date("August 19, 1975 23:15:30 GMT-11:00"); console.log(date1.getUTCDate()); // Expected output: 19 console.log(date2.getUTCDate()); // Expected output: 20 ... An integer, between 1 and 31, representing day of month ...
🌐
Futurestud.io
futurestud.io › tutorials › convert-a-date-to-utc-in-javascript-or-node-js
Convert a Date to UTC in JavaScript or Node.js - Future Studio
December 5, 2024 - Here’s the sample code using the getUTC<unit> methods to compose a date string without the T and Z characters. const date = new Date() const year = date.getUTCFullYear() const month = (date.getUTCMonth() + 1).toString().padStart(2, '0') const day = date.getUTCDate().toString().padStart(2, ...
🌐
Day.js
day.js.org › docs › en › plugin › utc
UTC · Day.js
var utc = require("dayjs/plugin/utc"); // import utc from 'dayjs/plugin/utc' // ES 2015 dayjs.extend(utc); // default local time dayjs().format(); //2019-03-06T17:11:55+08:00 // UTC mode dayjs.utc().format(); // 2019-03-06T09:11:55Z // convert local time to UTC time dayjs().utc().format(); // 2019-03-06T09:11:55Z // While in UTC mode, all display methods will display in UTC time instead of local time. // And all getters and setters will internally use the Date#getUTC* and Date#setUTC* methods instead of the Date#get* and Date#set* methods.
🌐
Jaketrent
jaketrent.com › post › javascript-dates-utc
JavaScript Dates and UTC - Jake Trent
April 11, 2023 - The format of the date going into the Date constructor changes what comes out when calling methods on it. To simplify, use UTC dates everywhere. Access it with .getUTC* methods. Beware that .getHours and other methods do automatic timezone conversions. Only convert to local time at the last moment.
🌐
TutorialsPoint
tutorialspoint.com › javascript › date_utc.htm
JavaScript Date.UTC() Method
<html> <body> <script> const utcDate = new Date(Date.UTC(2023, 0, 15, 12, 30, 0)); document.write(utcDate); </script> </body> </html> The resulting date object will be returned in UTC format.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › getUTCDay
Date.prototype.getUTCDay() - JavaScript - MDN - Mozilla
July 10, 2025 - const date1 = new Date("August 19, 1975 23:15:30 GMT+11:00"); const date2 = new Date("August 19, 1975 23:15:30 GMT-11:00"); // Tuesday console.log(date1.getUTCDay()); // Expected output: 2 // Wednesday console.log(date2.getUTCDay()); // Expected output: 3 ... An integer corresponding to the day of the week for the given date according to universal time: 0 for Sunday, 1 for Monday, 2 for Tuesday, and so on. Returns NaN if the date is invalid. The following example assigns the weekday portion of the current date to the variable weekday.