新的Date('yyyy-mm-dd')将时区设置为本地时区,但新的Date('yyyy-mm-dd')将时区设置为GMT [重复]

 收藏

新的Date('yyyy-mm-dd')将时区设置为本地时区,但是 新的Date('yyyy-mm-dd')将时区设置为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)

为什么会发生这种现象

回复
  • wquod 回复

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

    支持ISO 8601格式的不同之处在于,仅日期字符串(例如“ 1970-01-01”)被视为UTC,而非本地

    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.