在 IE9 Quirks 模式下 Date.parse 返回 NaN

发布于 2024-12-16 14:22:33 字数 590 浏览 4 评论 0原文

我试图弄清楚为什么当 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

纵情客 2024-12-23 14:22:34

首先你应该明白怪异模式基本上是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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文