javascript - 为什么这个日期在 iOS 和 Safari 上无效,但在 Chrome 和 Firefox 上无效?

标签 javascript datetime

为什么会这样:

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

返回

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

在我的笔记本电脑上使用 Firefox 和 Chrome 而不是

invalid date

在笔记本电脑上的 Safari 和 iOS 上的 Chrome 上?

最佳答案

因为网络浏览器不一致... :-(

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.

根据记录,new Date("2019-01-10T00:00:00+01:00")(在时区部分的小时和分钟之间有一个冒号)似乎在 Safari 上做正确的事。

关于javascript - 为什么这个日期在 iOS 和 Safari 上无效,但在 Chrome 和 Firefox 上无效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54121362/

相关文章:

javascript - 确认盒子样式

C# DateTime ToString 标准区域性格式

javascript - 如何检查字符串是否以 iFrame 开头?

javascript - Angular 访问范围属性

javascript 或 jquery - 获取 href 的最后 2 个字符

sql-server - 将 varchar dd/mm/yyyy 转换为 dd/mm/yyyy 日期时间

perl - 获取经度/纬度并在 Perl 中获取 UTC 偏移量

sql - 通过@timestamp查询ElasticSearch SQL过滤

r - 日期时间 - 确定多个(n)日期时间范围是否在 R 中相互重叠

javascript - 为什么添加 URL Hash 而不是替换?