开发者

What does it mean by the number of dates in Javascript's date() function?

I have simple question about Javascript date() function. This is a snippet of code

var today = new Date(); // current date
var xmas = new Date(2011,12,25); // this xmas
alert(Math.round ( today / (1000*60*60*24) ) ); // transform into n开发者_高级运维umber of days
alert(Math.round ( xmas / (1000*60*60*24) ) ); // transform into number of days

The output is as the following, respectively:

15141 // today
15364 // xmas

I don't know what does it mean by these numbers? 15141 (or 14999) days compare to what?

I also made another simple calculation to find the number of days from now to this year's xmas, to see if the above calculation is correct:

var total_days = Math.round(xmas/(1000*60*60*24)) - Math.round(today/(1000*60*60*24));
alert( total_days );

It returns 223 (days), this is correct.

So turning back to the orignal question, what does it mean by those numbers?


Javascript time starts at 1 January 1970 00:00:00 UTC. So its 14999 days since then.


You could refer to http://www.w3schools.com/jsref/jsref_gettime.asp When a dateObj is cast to int, the value would be equals to dateObj.getTime()


To Calculate the days, they often use a reference point. Here it is 01/01/1970, and its the same for java.

Infact goto http://www.timeanddate.com/date/duration.html

It calculates days between 2 dates,go there and verify your numbers

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜