问题描述
new Date(null)
// Date 1970-01-01T00:00:00.000Z
当我在JavaScript控制台中键入 new Date(null)
时会怎么办
日期1970-01-01T00:00:00.000Z
?
How come when I type new Date(null)
in JavaScript console I'm gettingDate 1970-01-01T00:00:00.000Z
?
推荐答案
因为ECMAScript 2017标准是这样吗?
Because the ECMAScript 2017 standard says so?
ECMA部分的结尾声明:
The end of ECMA section 20.3.1.1 claims:
...这可能会让您说: ...但是!但是!,我没有说+0,我说的是:
...which might make you say, "...but!, but!, I did not say +0, I said":
new Date(null)
好,所以让我们遵循该标准...
Ok, so let's follow the standard on that one...
该Date构造器示例转到,其中项目 3.b.iii 表示:
That Date constructor example goes to section 20.3.2.2, where item 3.b.iii there says:
ToNumber是一个超链接,因此请遵循部分,其中有一个数字转换表显示为:
ToNumber is a hyperlink, so follow that to section 7.1.3 where there is a number conversion table that shows:
因此:
new Date(null)
有效地变为:
new Date(+0)
这是为什么您最终得到:
Which is why you ultimately get:
这篇关于为什么新的Date(null)返回此:Date 1970-01-01T00:00:00.000Z?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!