Repository navigation
I can't set a default timezone on windows. #4230
Description
Activity
- addedquestionIssues asking questions about Node.js.Issues asking questions about Node.js.windowsIssues and PRs related to the Windows platform.Issues and PRs related to the Windows platform.
on Dec 10, 2015 Does it work when you set TZ on the command line? V8 calls
_tzset()on Windows, which respects TZ, but it runs quite early on.The same caveat applies to Unices; the fact that setting TZ inside the program works is luck more than anything else. If you want it to be reliable and future proof, run your program with
env TZ=UTC node app.js.Reacted by Steven R. Loomis@bnoordhuis Yes, I tried to set an environment variable,
set "TZ=UTC"is not work.What version of Windows is that? Do you get correct output after
tzutil /s UTC?Windows 10x64
Thu Dec 10 2015 12:42:57 GMT+0000
It works, but it changes the time zone of the OS.
It works, but it changes the time zone of the OS.
Right, but it confirms that the timezone calculation as such is correct once it has the right timezone.
/cc @nodejs/platform-windows - I'm fairly sure it's a V8 issue (relevant code here) but maybe you can take a look?
Is it even supposed to work the way it does on Linux? Is it documented anywhere?
V8 documentation? Surely you jest! If you're referring to
_tzset(), MSDN claims it honors TZ.No, I'm referring to how the TZ variable affects the behavior of
new Date()in Node.js.Correction:
new Date()is not affected, the implicittoString()call is.Reacted by Joe EkiertNeither we nor V8 document the effect of TZ, it's an artifact of the implementation.
- addedv8 engineIssues and PRs related to the V8 dependency.Issues and PRs related to the V8 dependency.
on Dec 10, 2015 If you're referring to _tzset(), MSDN claims it honors TZ.
GetTimeZoneInformation, however, does not - and that's where V8 gets timezone information from. I'm not sure if there is any point to the _tzset() call at all.
Closing as there does not appear to be anything for us to do in core on this. Can reopen if necessary.
Reacted by MehradReacted by Joe Ekiert, Kunwei Wang, Benjamin Dahl, usb248, Sargon Piraev, Sergio Morchón Poveda, Dony Sukardi, Mehrad, Danyal Babar, Untit1ed and 17 moreReacted by Joe Ekiert, Mehrad, John Ragone, Leandro Morais Azevedo, Jason and Simon Douglas47 remaining items
I can confirm this problem is solved in node version 17.0.1 using Windows 10
Reacted by Steven R. Loomis, joe-sam, Pavel Mickevic, Apostol Apostolov, Jiri Spac, Johnn Guerrero and Radosław Osadnikthank you for the fix 16cb4f7
I can confirm this problem is solved in node version 17.0.1 using Windows 10
works now:
node -v
v17.2.0OS Name: Microsoft Windows 10 Pro
OS Version: 10.0.19041 N/A Build 19041-console.log({ tz: process.env.TZ, offset: moment().utcOffset() }); // { tz: 'UTC', offset: 120 } # bad +console.log({ tz: process.env.TZ, offset: moment().utcOffset() }); // { tz: 'UTC', offset: -0 } # good
Could the fix for this issue be backported to Node 16 LTS?
Reacted by Claude Betancourt, Pavel Mickevic, Upendra Dhakal, Tiago Danin and Tiberiu PopescuCould the fix for this issue be backported to Node 16 LTS?
#38642 was included in Node.js 16.2.0.
Reacted by Upendra Dhakal and Tiago DaninReacted by tmeindle, Tiago Danin and Johnn GuerreroReacted by Upendra Dhakal, tmeindle, Tiago Danin and YonyIs this fix available on Node.js v14?
Is this fix available on Node.js v14?
No, it was not backported to Node.js v14.
What can be done to get it ported back to v14?
Nothing. v14 is out of support now.
Reacted by Richard LauNot working if send the timesatamp to contructor
$ node -pe "new Date(1685389932472)" 2023-05-29T19:52:12.472Z $ node -pe "new Date()" 2023-05-29T20:21:51.841Z $ set TZ="Europe/Kiev" && node -pe "new Date(1685389932472)" #still not working 2023-05-29T19:52:12.472Z
But timesatmp is
Mon May 29 2023 22:52:12 GMT+0300 (Eastern European Summer Time)@NisuSan - Time zones don't change the UTC representation of a timestamp.
@mattjohnsonpint Hmm, in browser it works fine. Any way, can you explain how to deal with timestamp and time zone in this case?
@NisuSan - The
Zat the end of the ISO 8601 / RFC 3339 formatted string represents "Zulu" time - which is another term for "UTC". Unix timestamps are also in terms of UTC (being the number of seconds or milliseconds since 1970-01-01T00:00:00.000Z). UTC is irrespective of time zones, thus time zones do not affect UTC output.If you're asking why you see UTC output instead of local output, that's because you're just printing a raw
Dateobject. You didn't call any function on it that creates a string. Unfortunately, the implementation of printing a rawDateobject is undefined. Some environments print the UTC representation (as if you printed the result of calling thetoISOStringfunction), and other environments print the local time representation (as if you printed the result of calling thetoStringfunction).I have asked for standardization of this, to avoid the type of confusion you encountered, but with no result. See whatwg/console#132
Reacted by AntonyIf you want to see the effect of the system time zone, and Node's support for changing it, then you'll need to call
toString- not just print the rawDateobject.on Windows:
set TZ=Europe/Kiev && node -pe "new Date(1685389932472).toString()" Mon May 29 2023 22:52:12 GMT+0300 (Eastern European Summer Time)Note: Make sure there are no quotes around the ID on Windows.
or on Linux / macOS :
TZ="Europe/Kiev" node -pe "new Date(1685389932472).toString()" Mon May 29 2023 22:52:12 GMT+0300 (Eastern European Summer Time)Reacted by Antony@mattjohnsonpint Great explanation, thanks!
- added a commit that references this issue
on May 22, 2026
This code works well on Linux but does not work on windows.
On windows i see timezone from my os.