gpt4 book ai didi

javascript - Date getTime() 在不同的机器上返回不同的值

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:58:04 25 4
gpt4 key购买 nike

根据 MDN , 新日期():

creates a JavaScript Date instance that represents a single moment in time. Date objects are based on a time value that is the number of milliseconds since 1 January, 1970 UTC

关于getTime():

Returns the numeric value of the specified date as the number of milliseconds since January 1, 1970, 00:00:00 UTC (negative for prior times).

为什么声明:

new Date(new Date(1, 0, 1).setFullYear(1)).getTime();

假设返回从 1970 年 1 月 1 日 00:00:00 UTC 到 01/01/0001 12:00:00 AM 的毫秒数,在不同的机器上给出不同的值,例如-62135600400000-62135596800000?本地时区(或系统时间?)是否会以某种方式影响此逻辑?

最佳答案

它在文档中指定:

Note: Where Date is called as a constructor with more than one argument, the specifed arguments represent local time. If UTC is desired, use new Date(Date.UTC(...)) with the same arguments.

关于javascript - Date getTime() 在不同的机器上返回不同的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34793707/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com