IE JavaScript日期解析错误 [英] IE JavaScript date parsing error

查看:105
本文介绍了IE JavaScript日期解析错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么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.

例如,在Windows XP的IE6中,字符串格式如下:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆