最小和最大日期 [英] Minimum and maximum date

查看:53
本文介绍了最小和最大日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道 Javascript Date 对象所允许的最小和最大日期是多少.我发现最小日期类似于公元前 200000 年,但我无法获得任何参考.

I was wondering which is the minimum and the maximum date allowed for a Javascript Date object. I found that the minimum date is something like 200000 B.C., but I couldn't get any reference about it.

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

Does anyone know the answer? I just hope that it doesn't depend on the browser.

以纪元时间"(= 1970-01-01 00:00:00 UTC+00 的毫秒数)为最佳答案.

An answer in "epoch time" (= milliseconds from 1970-01-01 00:00:00 UTC+00) would be the best.

推荐答案

来自 规范,§15.9.1.1:

Date 对象包含一个 Number,该 Number 指示特定时刻到一毫秒内.这样的数字称为时间值.时间值也可能是 NaN,表示 Date 对象不代表特定的时刻.

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.

时间在 ECMAScript 中以 UTC 时间 1970 年 1 月 1 日以来的毫秒为单位测量.在时间值中,闰秒被忽略.假设每天正好有 86,400,000 毫秒.ECMAScript Number 值可以表示从 –9,007,199,254,740,992 到 9,007,199,254,740,992 的所有整数;此范围足以测量从 UTC 时间 1970 年 1 月 1 日起向前或向后大约 285,616 年内的任何时刻的毫秒精度.

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.

ECMAScript Date 对象支持的实际时间范围略小:精确到 –100,000,000 天到 100,000,000 天,相对于 UTC 1970 年 1 月 1 日开始的午夜.这给出了 1970 年 1 月 1 日 UTC 任一侧 8,640,000,000,000,000 毫秒的范围.

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.

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

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 年).

The third paragraph being the most relevant. Based on that paragraph, we can get the precise earliest date per spec from new Date(-8640000000000000), which is Tuesday, April 20th, 271,821 BCE (BCE = Before Common Era, e.g., the year -271,821).

这篇关于最小和最大日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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