问题描述
在进行一些测试时,我发现浏览器之间出现了不一致的行为,具有以下javascript
In doing some testing I've found inconsistant behavior between browsers with the following javascript
new Date("2013-09-10T08:00:00").toString()
在IE和Firefox中,结果是
In IE and Firefox the result is
在Chrome中,结果是
In Chrome the result is
所以根据我阅读的脚本的日期字符串的格式,它说...
So according to my reading of the ECMA script of the format for Date strings it says...
但是在文档中对于new Date()构造函数,它说
However in the documentation for the "new Date()" constructor it says
- 让v为ToPrimitive(value)。
-
如果Type(v)为String,则
- Let v be ToPrimitive(value).
If Type(v) is String, then
a。解析v作为日期,与解析方法完全相同(15.9.4.2);让V为此日期的
值。
a. Parse v as a date, in exactly the same manner as for the parse method (15.9.4.2); let V be the time value for this date.
15.9.4.2 Date.parse(string)
15.9.4.2 Date.parse (string)
解析函数将ToString运算符应用于其参数,并将生成的字符串解释为日期
和时间;它返回一个Number,UTC时间值对应于
的日期和时间。字符串可能会被解释为本地时间,UTC
时间,或某个其他时区的时间,具体取决于
the String的内容。
The parse function applies the ToString operator to its argument and interprets the resulting String as a date and time; it returns a Number, the UTC time value corresponding to the date and time. The String may be interpreted as a local time, a UTC time, or a time in some other time zone, depending on the contents of the String.
任何想法哪个实现是正确的?
Any ideas which implementation is correct?
推荐答案
标准冲突。 ISO 8601 :
Standards clash. ISO 8601 states that:
ECMA :
Mozilla开发者表示(在20.3.1.15之下):
The current draft of ES6 says (under 20.3.1.15):
所以Mozilla的实现(将)正确。
so Mozilla's implementation is (will be) correct.
这篇关于不确定日期解析失踪时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!