新的日期()显示Chrome或Firefox中的不同结果 [英] new Date() shows differents results in Chrome or Firefox

查看:152
本文介绍了新的日期()显示Chrome或Firefox中的不同结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

奇怪的是,针对新Date()的不同浏览器会产生不同的结果。

Strange thing, different results in differente browser for a new Date().

在Chrome 45.0.2454.101 m:

new Date(2015,9,1)
Thu Oct 01 2015 00:00:00 GMT+0200 (W. Europe Daylight Time)

在Firefox 40.0.3中(默认检查器/控制台)

In Firefox 40.0.3 (default inspector/console)

new Date(2015,9,1)
Date 2015-09-30T22:00:00.000Z

其他信息

如果我在Firefox中试用FIREBUG扩展控制台,与Chrome一样好用。
发生了什么事?似乎Firefox没有计算偏移量,实际上它比正确日期落后2小时。
我在其他工作站上进行了测试,所有人似乎都有这个错误。

Additional info
If I try in Firefox with the console of FIREBUG extension, works well like Chrome. What's happening? Seems that Firefox doen'st count the offset, in fact it's 2 hour behind the correct date. I did the test on other workstation and all seems to have this "bug".

推荐答案

这只是调试控制台的行为。您显示的两个日期值都相同,并且是正确的值。您只是在Chrome中看到当地时间,而Firefox选择在调试控制台中显示UTC时间。

This is just the behavior of the debug console. The two date values you showed are both the same, and are the correct value. You're just seeing the local time in Chrome, while Firefox chooses to show the UTC time in the debug console.

更准确地说,Chrome,IE和大多数其他浏览器只需在对象上调用 .toString(),而Firefox则调用 .toISOString()

More accurately, Chrome, IE, and most other browsers simply call .toString() on the object, while Firefox is calling .toISOString().

请注意,Firefox有一个错误,我们显示错误的时间名称zone(标准而不是日光),但您可以看到调试器值与ISO8601 UTC值匹配。

Note that Firefox has a bug that us showing the wrong name of the time zone (Standard instead of Daylight), but you can see the debugger value matches the ISO8601 UTC value.

这篇关于新的日期()显示Chrome或Firefox中的不同结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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