你能创建低于公元前271800的日期吗?像恐龙时间? [英] Can you create dates that are lower than 271800 BC? Like dinosaur time?

查看:88
本文介绍了你能创建低于公元前271800的日期吗?像恐龙时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

低于-271,800 BC的任何东西都会抛出无效的日期错误。我们可以回去一百万年吗?还是十亿?日期对象可以让您在过去或将来无限期地描述任何日期吗?我该怎么做这样的事情?

解决方案

代表一百万年前的特定日期使我无意义。朱利安历如果星期几符合巴比伦系统?



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



---更新:这被接受,所以我将添加一个几个更具体的位。 ---



如另一个答案所述,根据 EcmaScript规范,第五版第164页(链接是.pdf。)


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



ECMAScript Date对象支持的实际时间范围是
略小于:1970年1月1日开始时相对于午夜测量的-100,000,000天至100,000,000天

UTC 。这样可以在1970年1月1日(UTC)的1月1日以前的
的范围内达到8,640,000,000,000,000毫秒。


但是,日期。它忽略了一些现实。一百万年前的日子更短(12秒),所以一些JavaScript数学将不准确。一周中的几天已经用不同的系统确定了。几个月的定义不同。所有的说,决定你真正需要代表。


This is as low as I can seem to go with javascript date:

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

Anything lower than -271,800 BC throws an invalid date error. Can we go back a million years? Or a billion? Can the date object allow you to describe any date infinitely in the past or future? How might I do something like this?

解决方案

Representing a particular date a million years ago strikes me as meaningless. Julian calendar? Should days of week honor the Babylonian system?

Create your own type for this, decide what you actually need to represent.

--- Updated: This was accepted, so I'll add a few more specific bits. ---

As mentioned in another answer, according to the EcmaScript spec, pg 164 of the fifth edition (link is a .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.

But, this is for theoretical dates. It ignores a few pieces of reality. Days were shorter (by 12 seconds) a million years ago, so some JavaScript math would be inaccurate. Days of the week have been determined with different systems. Months have been defined differently. All to say, decide what you really need to represent.

这篇关于你能创建低于公元前271800的日期吗?像恐龙时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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