JavaScript Internet Explorer中的日期错误无效 [英] Javascript Invalid Date Error in Internet Explorer

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

问题描述

相对简单的javascript这里,不知道为什么IE恨我(对待别人你想如何对待我想)。

Relatively simple javascript here, not sure why IE hates me (treat others how you want to be treated I suppose).

var newDate = new Date("2012, 11, 2 19:30:00:000");
alert(newDate);

这可以在Chrome和FF中工作,但IE输出无效日期

This works in Chrome and FF, but IE outputs "Invalid Date"

提示我 http://jsfiddle.net/k6yD6 /

推荐答案

提供给日期构造函数的字符串应为RFC2822或ISO 8601格式化日期。在你的例子中,它不是。尝试以下内容:

The string given to the date constructor should be an RFC2822 or ISO 8601 formatted date. In your example it isn't. Try the following:

new Date("2012-11-02T19:30:00.000Z");

或使用替代构造函数

new Date(2012, 11, 2, 19, 30, 0)

这篇关于JavaScript Internet Explorer中的日期错误无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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