Jump to content

Probably A Simple Question


Guest ctgunn

Recommended Posts

Guest ctgunn

So, I understand what this example is doing, and I understand how it's doing it. My question involves the 1000. Why do you start out multiplying by 1000 and how do you know that that's the number you need to be able to find out how long it's been since January 1, 1970. How would you come upon the number you need to start with for some other year, or maybe for a different day in a year?<html><body><script type="text/javascript">var minutes = 1000*60;var hours = minutes*60;var days = hours*24;var years = days*365;var d = new Date();var t = d.getTime();var y = t/years;document.write("It's been: " + y + " years since 1970/01/01!");</script></body></html>

Link to comment
Share on other sites

The getTime method of a date object returns a Unix timestamp, which is the elapsed time since 1/1/70. Sometimes the timestamp is given in seconds, and sometimes it's in milliseconds. In Javascript it's in milliseconds, so they multiply by 1000 to change the seconds to milliseconds. In other words, the years variable is the number of milliseconds in one year.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...