IE Date.parse方法返回带有时间字符串的日期的NaN [英] IE Date.parse method returns NaN for Date with Time string

查看:118
本文介绍了IE Date.parse方法返回带有时间字符串的日期的NaN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试使用时间戳字符串解析日期,它在IE中爆炸,但工作正常FireFox。

We are trying parse the date with timestamp string, it blows up in IE but works fine FireFox.

以下是代码

alert(新日期(Date.parse(2010-01-31T12:00:00.233467-05:00)));

alert(new Date(Date.parse("2010-01-31T12:00:00.233467-05:00")));

有没有想过让它在IE浏览器中运行?在此先感谢。

Any idea to make it work in IE browser? Thanks in advance.

推荐答案

如果您能以这种形式提交您的意见:

If you can put your input in this form:

YYYY/MM/DDThh:mm:ss

它会起作用。

例如:

alert(new Date(Date.parse('2010-01-31T12:00:00.233467-05:00'.replace(/\-/ig, '/').split('.')[0])));

如果你想要时区,那么你必须找到另一种方式

If you want the time zone, then you will have to find another way

这篇关于IE Date.parse方法返回带有时间字符串的日期的NaN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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