-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
I can't set a default timezone on windows. #4230
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Does it work when you set TZ on the command line? V8 calls 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 |
@bnoordhuis Yes, I tried to set an environment variable, |
What version of Windows is that? Do you get correct output after |
Windows 10x64
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 |
No, I'm referring to how the TZ variable affects the behavior of |
Correction: |
Neither we nor V8 document the effect of TZ, it's an artifact of the implementation. |
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. |
Hello, I've been struggling with same problem. I'm running production enviroment where I can't change zone for user - what should I do? Thanks! |
@pankleks the only solution I've come up for windows is: https://github.com/capaj/set-tz |
This problem still exists two years later. |
Setting the TZ environment variable has no effect on Windows; causing some date/time related tests to fail. See nodejs/node#4230
I've created a ugly batch script for this issue. package.json "scripts": {
"test": "jest",
"test:win": "bin/test.cmd"
} bin/test.cmd FOR /F "tokens=* USEBACKQ" %%F IN (`tzutil /g`) DO SET PREVIOUS_TZ=%%F
tzutil /s "UTC"
cmd.exe /c yarn test
tzutil /s "%PREVIOUS_TZ%" |
Fixes: nodejs#4230 Signed-off-by: James M Snell <jasnell@gmail.com>
Ok, updated #38642 it now supports setting $ set TZ="America/New_York"
$ node -pe "new Date().toString()" process.env.TZ = 'Etc/UTC'
console.log(new Date().toString()); |
As i noted in the PR, EST should be strongly discouraged. It's also almost certainly not what you want. (the east coast of n. america is in daylight time right now, |
Fixes: nodejs#4230 Signed-off-by: James M Snell <jasnell@gmail.com>
Fixes: nodejs#4230 Signed-off-by: James M Snell <jasnell@gmail.com>
Fixes: nodejs#4230 Signed-off-by: James M Snell <jasnell@gmail.com>
Fixes: nodejs#4230 Signed-off-by: James M Snell <jasnell@gmail.com>
Fixes: nodejs#4230 Signed-off-by: James M Snell <jasnell@gmail.com>
Fixes: nodejs#4230 Signed-off-by: James M Snell <jasnell@gmail.com>
I can confirm this problem is solved in node version 17.0.1 using Windows 10 |
thank you for the fix 16cb4f7
works now:
-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? |
#38642 was included in Node.js 16.2.0. |
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. |
Not 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 |
@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 If you're asking why you see UTC output instead of local output, that's because you're just printing a raw I have asked for standardization of this, to avoid the type of confusion you encountered, but with no result. See whatwg/console#132 |
If you want to see the effect of the system time zone, and Node's support for changing it, then you'll need to call on Windows:
Note: Make sure there are no quotes around the ID on Windows. or on Linux / macOS :
|
@mattjohnsonpint Great explanation, thanks! |
This code works well on Linux but does not work on windows.
On windows i see timezone from my os.
The text was updated successfully, but these errors were encountered: