Jump to content

Probably A Simple Question


Guest ctgunn
 Share

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.

Edited by justsomeguy
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...