Skip to content Skip to sidebar Skip to footer

Inconsistant Date Parsing With Missing Timezone

In doing some testing I've found inconsistant behavior between browsers with the following javascript new Date('2013-09-10T08:00:00').toString() In IE and Firefox the result is '

Solution 1:

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.


Solution 2:

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.


Post a Comment for "Inconsistant Date Parsing With Missing Timezone"