为什么新的Date(null)返回此:Date 1970-01-01T00:00:00.000Z? [英] Why new Date(null) is returning this: Date 1970-01-01T00:00:00.000Z?

查看:801
本文介绍了为什么新的Date(null)返回此:Date 1970-01-01T00:00:00.000Z?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 getting
Date 1970-01-01T00:00:00.000Z?

推荐答案

因为ECMAScript 2017标准是这样吗?

Because the ECMAScript 2017 standard says so?

ECMA部分的结尾 20.3.1.1 声明:

The end of ECMA section 20.3.1.1 claims:


确切的午夜时刻在1970年1月1日开始时,UTC 由值+0 表示。

...这可能会让您说: ...但是!但是!,我没有说+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构造器示例转到 20.3.2.2 ,其中项目 3.b.iii 表示:

That Date constructor example goes to section 20.3.2.2, where item 3.b.iii there says:


3.b.iii:否则,让V为ToNumber(v)。

3.b.iii: Else, let V be ToNumber(v).

ToNumber是一个超链接,因此请遵循 7.1.3 部分,其中有一个数字转换表显示为:

ToNumber is a hyperlink, so follow that to section 7.1.3 where there is a number conversion table that shows:


参数类型结果

Null      | +0

Argument Type  | Result
Null                       | +0

因此:

new Date(null)

有效地变为:

new Date(+0)

这是为什么您最终得到:

Which is why you ultimately get:


Date 1970-01-01T00:00:00.000Z

Date 1970-01-01T00:00:00.000Z

这篇关于为什么新的Date(null)返回此:Date 1970-01-01T00:00:00.000Z?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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