Nope, it does not work. Date.UTC returns unix epoch time (milliseconds since UTC midnight on 1 Jan 1970) as an integer. When you use that to construct a new Date it will still be converted to the local time zone.
// zero-based months 🙄newDate(Date.UTC(2018,0/* Jan */,1))<-SunDec31201718:00:00GMT-0600(CentralStandardTime)
The only reason the linked example prints GMT time zone is because Date.toUTCString() is used. But when using the JS Date object, calculations will be off by a day behind in my local time zone.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Nope, it does not work.
Date.UTC
returns unix epoch time (milliseconds since UTC midnight on 1 Jan 1970) as an integer. When you use that to construct anew Date
it will still be converted to the local time zone.The only reason the linked example prints GMT time zone is because
Date.toUTCString()
is used. But when using the JS Date object, calculations will be off by a day behind in my local time zone.