简体   繁体   中英

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

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?

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 (eg "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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM