IE新日期(字符串)在做什么?

时间:2015-04-30 21:03:36

标签: javascript internet-explorer datetime

好的,所以质量保证给了我这个错误,如果一个日期有一个字符从日期的一个月,一天或一年开始(格式化MM / dd / yyyy),那(只在IE中)它会解析日期但是改变它..所以挖掘并确定它非常奇怪..

这是我在IE中讨论的一些示例代码

$("#dates").append("<li>04/30/2012 = " + new Date("04/30/2012").toString()+"</li>");
$("#dates").append("<li>a04/30/2012 = " + new Date("a04/30/2012").toString() +"</li>");
$("#dates").append("<li>b04/30/2012 = " + new Date("b04/30/2012").toString() +"</li>");
$("#dates").append("<li>c04/30/2012 = " + new Date("c04/30/2012").toString() +"</li>");
$("#dates").append("<li>d04/30/2012 = " + new Date("d04/30/2012").toString() +"</li>");
$("#dates").append("<li>e04/30/2012 = " + new Date("e04/30/2012").toString() +"</li>");
$("#dates").append("<li>04/a30/2012 = " + new Date("04/a30/2012").toString() +"</li>");
$("#dates").append("<li>04/b30/2012 = " + new Date("04/b30/2012").toString() +"</li>");
$("#dates").append("<li>04/c30/2012 = " + new Date("04/c30/2012").toString() +"</li>");
$("#dates").append("<li>04/d30/2012 = " + new Date("04/d30/2012").toString() +"</li>");
$("#dates").append("<li>04/e30/2012 = " + new Date("04/e30/2012").toString() +"</li>");
$("#dates").append("<li>04/30/a2012 = " + new Date("04/30/a2012").toString() +"</li>");
$("#dates").append("<li>04/30/b2012 = " + new Date("04/30/b2012").toString() +"</li>");
$("#dates").append("<li>04/30/c2012 = " + new Date("04/30/c2012").toString() +"</li>");
$("#dates").append("<li>04/30/d2012 = " + new Date("04/30/d2012").toString() +"</li>");
$("#dates").append("<li>04/30/e2012 = " + new Date("04/30/e2012").toString() +"</li>");

这是IE输出

•04/30/2012 = Mon Apr 30 2012 00:00:00 GMT-0500 (Central Daylight Time)
•a04/30/2012 = Sun Apr 29 2012 20:00:00 GMT-0500 (Central Daylight Time)
•b04/30/2012 = Sun Apr 29 2012 21:00:00 GMT-0500 (Central Daylight Time)
•c04/30/2012 = Sun Apr 29 2012 22:00:00 GMT-0500 (Central Daylight Time)
•d04/30/2012 = Sun Apr 29 2012 23:00:00 GMT-0500 (Central Daylight Time)
•e04/30/2012 = Mon Apr 30 2012 00:00:00 GMT-0500 (Central Daylight Time)
•04/a30/2012 = Fri Apr 29 -2012 20:00:00 GMT-0500 (Central Daylight Time)
•04/b30/2012 = Fri Apr 29 -2012 21:00:00 GMT-0500 (Central Daylight Time)
•04/c30/2012 = Fri Apr 29 -2012 22:00:00 GMT-0500 (Central Daylight Time)
•04/d30/2012 = Fri Apr 29 -2012 23:00:00 GMT-0500 (Central Daylight Time)
•04/e30/2012 = Sat Apr 30 -2012 00:00:00 GMT-0500 (Central Daylight Time)
•04/30/a2012 = Sun Apr 29 2012 20:00:00 GMT-0500 (Central Daylight Time)
•04/30/b2012 = Sun Apr 29 2012 21:00:00 GMT-0500 (Central Daylight Time)
•04/30/c2012 = Sun Apr 29 2012 22:00:00 GMT-0500 (Central Daylight Time)
•04/30/d2012 = Sun Apr 29 2012 23:00:00 GMT-0500 (Central Daylight Time)
•04/30/e2012 = Mon Apr 30 2012 00:00:00 GMT-0500 (Central Daylight Time)

有一些奇怪的小时添加的事情,除非你在格式的日期部分添加一个字符,然后它翻转年份到BC(从2012年到2012年???)

我们使用日期选择器,所以发生这种情况的可能性非常有限(但你​​知道QA人员是对的; - )......)那么其他人如何处理这种非常奇怪的行为呢? (仅供参考:我查了一下,但它需要一个MM / dd / yyyy日期并将其传递给浏览器日期解析器,所以没有骰子。

1 个答案:

答案 0 :(得分:3)