javascript - 您可以创建低于 271800 BC 的日期吗?像恐龙时代?

标签 javascript object date datepicker

这是我对 javascript 日期的最低要求:

var myDate = new Date(0, 0, 1);
myDate.setFullYear("-271800");
alert(myDate);

任何低于 -271,800 BC 的日期都会引发无效日期错误。我们能回到一百万年前吗?还是十亿?日期对象可以让你描述无限过去或 future 的任何日期吗?我该如何做这样的事情?

最佳答案

表示一百万年前的特定日期让我觉得毫无意义。儒略历?星期几应该遵守 Babylonian系统?

为此创建您自己的类型,确定您实际需要表示的内容。

--- 更新:这已被接受,所以我将添加一些更具体的内容。 ---

如另一个答案中所述,根据 EcmaScript spec, pg 164 of the fifth edition (链接是 .pdf。)

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,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.

但是,这是理论日期。它忽略了一些现实。一百万年前的日子更短(缩短了 12 秒),因此一些 JavaScript 数学计算是不准确的。星期几由不同的系统确定。月份的定义不同。总而言之,决定你真正需要代表什么。

关于javascript - 您可以创建低于 271800 BC 的日期吗?像恐龙时代?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8860297/

相关文章:

java - 如何获取当前午夜以来的毫秒数?

javascript - 如何在 netbeans jsp 应用程序中设置浏览器兼容性

javascript - redux-form 字段参数为空

javascript - 当 ui-router 状态改变时清除共享的 AngularJS Controller 变量

javascript - 返回新形式的数组 - javascript

date - Robocopy 最后修改 : more accurate than a day?

javascript - 使用 Javascript/jQuery 验证英国日期

javascript - document.getElementById 不返回任何值

Python类: Employee management system

javascript - 更改 JavaScript 对象键和数据的位置