Why is this date invalid on iOS and Safari but not in Chrome and Firefox?

Viewed 94

Why does this:

new Date("2019-01-10T00:00:00+0100")

return

Thu Jan 10 2019 00:00:00 GMT+0100 (Central European Standard Time)

on Firefox and Chrome on my laptop but instead

invalid date

on Safari on laptop and on Chrome on iOS?

1 Answers

Because web browsers are inconsistent... :-(

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

Note: parsing of date strings with the Date constructor (and Date.parse, they are equivalent) is strongly discouraged due to browser differences and inconsistencies. Support for RFC 2822 format strings is by convention only. Support for ISO 8601 formats differs in that date-only strings (e.g. "1970-01-01") are treated as UTC, not local.

For the record, new Date("2019-01-10T00:00:00+01:00") (with a colon between the hour and the minute in the timezone part) seems to do the right thing on Safari.

Related