-3

What is the explanation for such behavior ?

> new Date('2017-12-01T22:35:20').getDay()
5
> new Date('2017-12-01T22:35:20Z').getDay()
6

serhii kuzmych
  • 187
  • 3
  • 9
  • 2
    What timezone are you in? It'll be at least UTC+2 and the difference will be due to that. The `Z` denotes Zulu time/GMT/UTC and without anything specifiying the time zone it will be treated as local. – phuzi Mar 21 '23 at 10:16
  • 1
    from the [spec](https://262.ecma-international.org/7.0/#sec-date-time-string-format): *'When the time zone offset is absent, ... date-time forms are interpreted as a local time.'* see: [What are valid Date Time Strings in JavaScript?](https://stackoverflow.com/questions/51715259/what-are-valid-date-time-strings-in-javascript) – pilchard Mar 21 '23 at 10:17

1 Answers1

3

Z means 'Zulu time', AKA 'UTC'. If you omit the Z you get a Date object in your local timezone.

Evert
  • 93,428
  • 18
  • 118
  • 189