gpt4 book ai didi

javascript - 最小和最大日期

转载 作者:IT王子 更新时间:2023-10-29 02:39:44 25 4
gpt4 key购买 nike

我想知道 Javascript Date 对象允许的最小和最大日期是哪个。我发现最小日期大约是公元前 200000 年,但我无法获得任何相关引用。

有人知道答案吗?我只是希望它不依赖于浏览器。

“纪元时间”(= 从 1970-01-01 00:00:00 UTC+00 开始的毫秒数)的答案是最好的。

最佳答案

来自 the spec, §15.9.1.1 :

A Date object contains a Number indicating a particular instant in time to within a millisecond. Such a Number is called a time value. A time value may also be NaN, indicating that the Date object does not represent a specific instant of time.

Time is measured in ECMAScript in milliseconds since 01 January, 1970 UTC. In time values 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,992 to 9,007,199,254,740,992; 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.

第三段最相关。根据该段,我们可以从 new Date(-8640000000000000) 中获取每个规范的准确最早日期,即公元前 271,821 年 4 月 20 日星期二(BCE = Before Common Era,例如,年份-271,821).

关于javascript - 最小和最大日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11526504/

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