gpt4 book ai didi

javascript - JavaScript 的 Date 对象容易受到 Y2038 问题的影响吗?

转载 作者:搜寻专家 更新时间:2023-11-01 04:42:24 24 4
gpt4 key购买 nike

假设是 32 位操作系统/浏览器,如果我将日期设置为 2038 年之后,用 JavaScript 创建的 Date 对象是否可以翻转到 1970 年?

Mozilla documentation说一年可以设置为 9999,但是我不知道这是否在所有 JavaScript 实现中都是一致的,或者这是否是对规范规定内容的准确描述。

我认为根据文档中的措辞,它似乎要么使用 64 位数字来存储时间,要么以 ISO 日期格式存储实际数据。

有谁知道浏览器是如何实现的?

最佳答案

根据ECMAScript specification,这不应该是第 15.9.1.1 节:

Time is measured in ECMAScript in milliseconds since 01 January, 1970 UTC. Leap seconds are ignored. It is assumed that there are exactly 86,400,000 milliseconds per day. ECMAScript number values can represent all integers from –9,007,199,254,740,991 to 9,007,199,254,740,991; this range suffices to measure times to millisecond precision for any instant that is within approximately 285,616 years, either forward or backward, from 01 January, 1970 UTC.

The actual range of times supported by ECMAScript Date objects is slightly smaller: exactly –100,000,000 days to 100,000,000 days measured relative to midnight at the beginning of 01 January, 1970 UTC.

This gives a range of 8,640,000,000,000,000 milliseconds to either side of 01 January,1970 UTC. The exact moment of midnight at the beginning of 01 January, 1970 UTC is represented by the value +0.

关于javascript - JavaScript 的 Date 对象容易受到 Y2038 问题的影响吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13482074/

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