new Date('yyyy-mm-dd') 将时区设置为本地时区,但是 new Date('yyyyy-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)
为什么会出现这种行为
最佳答案
您的第一个是创建 UTC 日期,但您以本地时区显示它。来自 documentation ...
Support for ISO 8601 formats differs in that date-only strings (e.g. "1970-01-01") are treated as UTC, not local
正在以您本地时区创建您的第二个日期。这样做的原因是因为ISO 8601 standard only supports a 4-digit year (默认),因此不符合上述条件。
关于javascript - new Date ('yyyy-mm-dd' ) 将时区设置为本地时区,但 new Date ('yyyyy-mm-dd' ) 将时区设置为 GMT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56371973/