mercredi 5 décembre 2018

'new Date()' in IE11 does not accept string in ISO 8701 date format with a timezone

The following call to the Date constructor call works in Chrome, Mozilla, and Edge, but not in IE11:

new Date("2018-11-01T04:00:00.000+1000");

Note: I receive the date string from server response and therefore, I have no control over it

In IE11 only, I get Invalid Date as a returned value. I figured out that it was because of the format of the timezone marker (+ onward) because the following call works as intended:

new Date("2018-11-01T04:00:00.000"); // No timezone

As well as this one:

new Date("2018-11-01T04:00:00.000+10:00"); // Formatted timezone

What ways are there to get a Date object from the string "2018-11-01T04:00:00.000+1000" in IE11?

Splicing the : in the appropriate place seems to do the job, but I am not sure it is the best solution.

Thank you!




Aucun commentaire:

Enregistrer un commentaire