Unix时间戳在JavaScript中不正确,但根据其他来源正确

问题描述

根据1604978063,此时间戳new Date(1604978063)不正确

它返回以下内容:

Date Mon Jan 19 1970 05:49:38 GMT-0800 (Pacific Standard Time)

当我在DuckDuckGo上查找时,它看起来是正确的。

DDG results

这是怎么回事?

解决方法

Javascript的时间戳不是标准的unix时间戳。他们使用毫秒,因此需要乘以1000:

new Date(1604978063 * 1000)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...