IE JavaScript 日期解析错误 [英] IE JavaScript date parsing error
问题描述
为什么 IE 无法将此字符串解析为 Date 对象.
Why cannot IE parse this string as a Date object.
var d = Date.parse("Fri Jun 11 04:55:12 +0000 2010"); // returns NaN
但是,它在 FireFox 中运行良好.我正在运行 IE 8.
However, it works well in FireFox. I am running IE 8.
谢谢.
推荐答案
您在 IE 8 中获得 NaN
值并且它在 Firefox 中工作,因为字符串的格式因浏览器和操作系统而异.
You are getting NaN
value in IE 8 and its working in Firefox because the format of the string varies with browser and operating system.
例如在IE6 for Windows XP中,字符串格式如下:
For example, in IE6 for Windows XP, the string is in the following format:
Tue Dec 05 16:47:20 CDT 2006
但在 Firefox for Windows XP 中,字符串是
But in Firefox for Windows XP, the string is
Tue Dec 05 2006 16:47:20 GMT-0500
要使其与两种浏览器兼容,您必须首先检查您的浏览器javascript 代码,然后相应地给出您输入的日期字符串.
to make it compatible with both browser you will have to first check the browser in your javascript code and then accordingly give your input date string.
这篇关于IE JavaScript 日期解析错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!