Home > database >  JS Date doesn't react to DST change
JS Date doesn't react to DST change

Time:05-23

I have tested new Date() in the console and the return value doesn't depend on The difference between my PC's time and my browser's time
Look at the time difference in console and in the Windows taskbar. Thay are not the same.
How to fix that?

CodePudding user response:

JavaScript is doing the right thing. However, most browsers (Chrome, etc.) will only detect a change to Window's "Adjust for daylight saving time automatically" setting when all browser windows are closed and the browser is restarted.

That said, my best advice is that you should never turn the "Adjust for daylight saving time automatically" setting off. The setting only exists as an artifact of Window's history, and is only needed in some very rare edge cases these days. Leave it on.

You should also have "Set time automatically" turned on, as that will synchronize your computer's clock to the Internet.

For time zones, you can try using "Set time zone automatically" - which works in many cases but can sometimes pick the wrong time zone if you are connecting through a VPN. You can also turn that off and just pick your time zone from the list of time zones.


Just to demonstrate how buggy turning "Adjust for daylight saving time automatically" off can be, below is a screenshot from my fully updated Windows 11 machine. Notice if I turn it off that the time in the settings panel is an hour off from the time in the task bar. That is a bug in Windows that has appeared before and has apparently regressed again. Best to avoid it.

enter image description here

CodePudding user response:

The Date.now() method ...

returns the numeric value corresponding to the current time—the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC, with leap seconds ignored.

From this MDN page

Note it's UTC, which answers the question.

  • Related