新的Date('yyyy-mm-dd')将时区设置为本地时区,但新的Date('yyyy-mm-dd')将时区设置为GMT [英] new Date('yyyy-mm-dd') sets timezone to local timezone but new Date('yyyyy-mm-dd') sets timezone to GMT
问题描述
new Date('yyyy-mm-dd')将时区设置为本地时区,但是
new Date('yyyy-mm-dd')将时区设置为GMT
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)
为什么会发生这种情况
推荐答案
您的第一个一种是创建UTC日期,但您将其显示在本地时区。从文档 ...
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,而不是UTC。 local
Support for ISO 8601 formats differs in that date-only strings (e.g. "1970-01-01") are treated as UTC, not local
您的第二个日期是在您当地的时区中创建的。原因是因为 ISO 8601标准仅支持4位数字的年份(默认情况下),因此它不符合上述条件。
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.
这篇关于新的Date('yyyy-mm-dd')将时区设置为本地时区,但新的Date('yyyy-mm-dd')将时区设置为GMT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!