I had the same issue. I get a date as a String, for example: '2016-08-25T00:00:00', but I need to have the Date object with correct time. To convert String into object, I use getTimezoneOffset:

var date = new Date('2016-08-25T00:00:00')
var userTimezoneOffset = date.getTimezoneOffset() * 60000;
new Date(date.getTime() + userTimezoneOffset);

getTimezoneOffset() will return ether negative or positive value. This must be subtracted to work in every location in world.

Answer from wawka on Stack Overflow
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 Timezone manipulation in JavaScript. More on stackoverflow.com
🌐 stackoverflow.com
javascript - Get a UTC timestamp - Stack Overflow
Releases Keep up-to-date on features we add to Stack Overflow and Stack Internal. ... Find centralized, trusted content and collaborate around the technologies you use most. Learn more about Collectives ... Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... Closed 13 years ago. How can I get the current UTC timestamp in JavaScript... 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
November 26, 2015
JavaScript - Parse UTC Date - Stack Overflow
How can I parse a simple date string and let JavaScript know that it's actually a UTC date? Currently, if I do new Date('2015-08-27') it converts it to my timezone. More on stackoverflow.com
🌐 stackoverflow.com
🌐
Stack Five
stackfive.io › work › javascript › how-to-display-utc-date-in-javascript
How To Display UTC Date In Javascript
January 25, 2023 - You pass in a date string along the lines of "2023-01-01" to the built-in Date constructor, and what you get is: 1const dateString = "2023-01-01" 2const date = new Date(dateString) 3 4console.log(date) 5//Sat Dec 31 2022 19:00:00 GMT-0500 (Eastern ...
🌐
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.
🌐
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
🌐
W3Schools
w3schools.com › jsref › jsref_toutcstring.asp
JavaScript Date toUTCString() Method
The toUTCString() method returns a date object as a string, according to UTC. Tip: The Universal Coordinated Time (UTC) is the time set by the World Time Standard. Note: UTC time is the same as GMT time. toUTCString() is an ECMAScript1 (JavaScript ...
🌐
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 » ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: ...
Find elsewhere
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
🌐
GitHub
github.com › date-fns › utc
GitHub - date-fns/utc: date-fns UTC utils · GitHub
The package provides Date extensions UTCDate and UTCDateMini that perform all calculations in UTC rather than the system time zone. Using it makes date-fns operate in UTC but can be also used without it.
Starred by 142 users
Forked by 5 users
Languages   TypeScript 55.8% | JavaScript 29.9% | Shell 7.7% | Makefile 6.4% | Dockerfile 0.2%
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › getUTCDate
Date.prototype.getUTCDate() - JavaScript - MDN Web Docs
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 ...
🌐
Jaketrent
jaketrent.com › post › javascript-dates-utc
JavaScript Dates and UTC - Jake Trent
April 11, 2023 - If you want to specify the parts of the date separately but get a UTC date, see the fromLocalToUtc implementation below. If you want to specify the timezone using an IANA Timezone ID, see the article on setting timezones on JavaScript dates.
🌐
CoreUI
coreui.io › answers › how-to-get-the-utc-date-in-javascript
How to get the UTC date in JavaScript · CoreUI
October 27, 2025 - From my expertise, the most reliable approach is using the built-in UTC methods like getUTCFullYear(), getUTCMonth(), and getUTCDate() to extract timezone-independent values. This ensures consistent date handling regardless of the user’s local ...
🌐
Reddit
reddit.com › r/javascript › how to really get a utc date object
r/javascript on Reddit: How to REALLY get a UTC Date object
November 26, 2015 -

I have a timestamp (e.g. 2015-10-11T14:03:19.243) and I need to get a UTC (timezone agnostic) Date object from javascript so I can use the strftime library. I have been having a hell of a time with this and I have no idea why nothing is working. Whenever I create a new Date with that timestamp I get that time in my browsers timezone...

Typically I would just use Moment.js for this but since it's relatively large I can't as I need to keep this app as lightweight as possible

🌐
TutorialsPoint
tutorialspoint.com › javascript › date_getutcdate.htm
JavaScript Date getUTCDate() Method
The following example demonstrates the usage of JavaScript Date getUTCDate() method − · <html> <body> <script> const currentDate = new Date(); const dayOfMonth = currentDate.getUTCDate(); document.write(dayOfMonth); </script> </body> </html> ...
🌐
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.
🌐
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, ...
🌐
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 - When we need to create a date in UTC we can use the moment.utc() method and pass the specific date and time as arguments.