0

When using Date constructor, adding a leading zero to the month adds additional shift to hours (possibly according to the timezone.) Is there any logic reason behind this behaviour?

new Date('2020-03-25') → Mar 25 2020 01:00:00 GMT+0100
new Date('2020-3-25') → Mar 25 2020 00:00:00 GMT+0100
Maciek Jurczyk
  • 555
  • 3
  • 7
  • Does this answer your question? [Why does Date.parse give incorrect results?](https://stackoverflow.com/questions/2587345/why-does-date-parse-give-incorrect-results) (`new Date(string)` uses `Date.parse(string)` under the covers). – Heretic Monkey Mar 25 '20 at 16:05
  • You should not rely on `new Date()` to parse date strings in any format other than `YYYY-MM-DD hh:mm:ss` – Niet the Dark Absol Mar 25 '20 at 16:05
  • This might be caused by the fact that depending on the language / culture, it might be interpreted as a date from a specific timezone. For example, ["German grammar rules do not allow for leading zeros in dates at all"](https://en.wikipedia.org/wiki/Date_and_time_notation_in_Europe) – Seblor Mar 25 '20 at 16:15

0 Answers0