I recently installed a plugin on chrome that allows me to change the timezone, this allowed me to notice an unexpected behavior of the javaScript Date object.
In fact, setting the following date by Date construtor, new Date (2022,1,1)
and London TimeZone, the date is not 01 February 2022 but Mon Jan 31 2022 23:00:00 GMT + 0000 (London Standard Time)
.
I don't understand if this is correct behavior or there is something I cannot grasp.
Asked
Active
Viewed 46 times
2

Federcio
- 67
- 3
-
2Please research your inquiry before posting in accordance with [ask]. Duplicate of [Incorrect date shown in new Date() in JavaScript](https://stackoverflow.com/questions/39223481/incorrect-date-shown-in-new-date-in-javascript) – esqew Feb 27 '22 at 14:50
-
3@esqew - What makes you think it's a duplicate of that? The OP is using the multi-argument version of `new Date`, which works in local time. The OP claims they've set local time to "London" via the extension ("plugin"). If they had, then `new Date(2022, 1, 1)` should give them UTC 2022-02-01T00:00:00, not what they say they're getting (since London uses GMT in February, and GMT is UTC [handwaving a couple of irrelevant details]). – T.J. Crowder Feb 27 '22 at 14:53
-
2It sounds like the extension you've installed isn't working reliably. I wouldn't use it. It happens I live in the same timezone as London. `new Date(2022, 1, 1).toString()` gives me `"Tue Feb 01 2022 00:00:00 GMT+0000 (Greenwich Mean Time)"` as I'd expect. (Note: I've never heard of "London Standard Time" and don't think such a thing exists. The UK uses "Greenwich Mean Time" or [in the "summer"] "British Summer Time" which is GMT+01:00.) – T.J. Crowder Feb 27 '22 at 14:54
-
@T.J. Crowder Thank you so much for the answer, I suspected just that. – Federcio Feb 27 '22 at 15:01