Inconsistant date parsing with missing timezone

后端 未结 2 767
抹茶落季
抹茶落季 2021-01-06 18:05

In doing some testing I\'ve found inconsistant behavior between browsers with the following javascript

new Date(\"2013-09-10T08:00:00\").toString()


        
相关标签:
2条回答
  • 2021-01-06 18:35

    There are several questions on stackoverflow.com that address this issue. I gave a rather thorough explanation here if anyone reading this is interested in the browser-to-browser details.

    The bottom line though is, for now at least, you should either avoid the ISO 8601 format all together or ALWAYS include a timezone specifier when using it. And, never use the 'YYYY-MM-dd' format because it gets interpreted as a short version of ISO 8601 without a time zone specifier.

    0 讨论(0)
  • 2021-01-06 18:43

    Standards clash. ISO 8601 states that:

    If no UTC relation information is given with a time representation, the time is assumed to be in local time.

    ECMA says:

    The value of an absent time zone offset is “Z”.

    Mozilla devs think that ISO takes precedence, Chrome folks seem to disagree.

    The current draft of ES6 says (under 20.3.1.15):

    If the time zone offset is absent, the date-time is interpreted as a local time.

    so Mozilla's implementation is (will be) correct.

    0 讨论(0)
提交回复
热议问题