2

new Date('yyyy-mm-dd') sets timezone to local timezone but new Date('yyyyy-mm-dd') sets timezone to GMT

new Date("2019-05-29")
Wed May 29 2019 05:30:00 GMT+0530 (India Standard Time)

new Date("11111-05-29")
Mon May 29 11111 00:00:00 GMT+0530 (India Standard Time)

Why does this behavior occur

Gokul
  • 82
  • 8
  • 2
    See [Differences in assumed time zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse#Differences_in_assumed_time_zone) – Herohtar May 30 '19 at 05:18

1 Answers1

2

Your first one is creating a UTC date but you're displaying it in your local timezone. From the documentation...

Support for ISO 8601 formats differs in that date-only strings (e.g. "1970-01-01") are treated as UTC, not local

Your second date is being created in your local timezone. The reason for this is because the ISO 8601 standard only supports a 4-digit year (by default), therefore it does not qualify for the above condition.

Phil
  • 157,677
  • 23
  • 242
  • 245