在 IE9 Quirks 模式下 Date.parse 返回 NaN
我试图弄清楚为什么当 IE9 处于 Quirks 模式时,Date.parse (javascript) 在应用于看似有效的 ISO 8601 日期字符串时会返回 NaN。它在标准模式下运行良好。
//ReturnsNaN in Quirks Mode, 1270574382557 in Standards Mode
document.write(Date.parse("2010-04-06T17:19:42.557"));
//Returns NaN in Quirks Mode, 1270512000000 in Standards Mode
document.write(Date.parse("2010-04-06"));
相比之下,以下内容对我来说适用于怪癖和标准
//Returns 1270549182000 in both Quirks and Standards Modes
document.write(Date.parse("2010/04/06T17:19:42"));
还有其他人看到这种行为吗?如果是这样,关于为什么 Date.parse 返回 NaN 有什么想法吗?
I am trying to figure out why Date.parse (javascript) returns NaN when applied to a seemingly valid ISO 8601 date string when IE9 is in Quirks Mode. It works fine in Standards mode.
//ReturnsNaN in Quirks Mode, 1270574382557 in Standards Mode
document.write(Date.parse("2010-04-06T17:19:42.557"));
//Returns NaN in Quirks Mode, 1270512000000 in Standards Mode
document.write(Date.parse("2010-04-06"));
In contrast, the following works in both Quirks and Standards for me
//Returns 1270549182000 in both Quirks and Standards Modes
document.write(Date.parse("2010/04/06T17:19:42"));
Is anybody else seeing this behavior? If so, any ideas on why Date.parse is returning NaN?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先你应该明白怪异模式基本上是IE5兼容模式。
它是由于没有有效的声明而触发的。
主要影响是它导致浏览器使用 IE5 盒子模型,这意味着所有填充、边距和边框以及影响盒子大小的其他任何内容都将不正确。
所以你的 Date.parse 不起作用,因为在这些日期没有这样的功能 - “解析 ISO 8601 日期”。
First of all you should understand that quirks mode is basically an IE5 compatibility mode.
It is triggered by not having a valid declaration.
The main effect is that it causes the browser to use the IE5 box-model, which means that all your paddings, margins and borders, and anything else which affects the size of a box will be incorrect.
So your Date.parse doesn't work because there were no such feature - "parse ISO 8601 date" at those dates.