<!-- Time passed since Jan 1st 1970 -->
var minutes = 1000*60; <!-- clock ticks in a minute -->
var hours = minutes*60; <!-- in an hour -->
var days = hours*24; <!-- in a day -->
var years = days*365; <!-- in a year -->
var d = new Date(); <!-- start with today -->
var t = d.getTime(); <!-- the # of seconds since 1/1/1970 -->
var y = t/years; <!-- how many years in the whole mess -->
document.write("<b>"+d+"</b><p>");
document.write("It's been: " + y + " years since Jan 1st, 1970<p>"); <
<!-- Start fresh -->
var quarter = (years * 4) + days; <!-- days in four years, (plus leap day) -->
var Months = Array(); <!-- days in each month -->
Months[0] = 31; Months[1] = 28; Months[2] = 31; Months[3] = 30;
Months[4] = 31; Months[5] = 30; Months[6] = 31; Months[7] = 31;
Months[8] = 30; Months[9] = 31; Months[10] = 30; Months[11] = 31;
m = d.getFullYear(); <!-- get the current year -->
v = 1970;
a = 0; x = 0; z = 0;
while (v < m) <!-- get accurate leap year count in period-->
{
if ((v % 4) == 0)
{
a += 1; <!-- accumulate leap year count -->
z += 366; <!-- accumulate days in period -->
}
else
{
z += 365; <!-- accumulate days in period -->
}
v += 1; <!-- increment comparison year -->
x += 1; <!-- accumulate years in period -->
}
document.write ("It is now "+v+", and there have been ");
document.write (a+" leap years since 1970<br>");
w = t - (z * days); <!-- subtract days before 1/1/ThisYear -->
<!-- at this point, w = the time elapsed since Jan 1st of this year and we -->
<!-- want to know how many months, days, hours, minutes and seconds it -->
<!-- represents -->
a = 0; b = 0; n = 0;
if ((m % 4)==0) {Months[1]=29;} <!-- if it's a leap year -->
while (w > (Months[a] * days))
{
w -= (Months[a] * days); <!-- subtract this month's days -->
a += 1; <!-- point to the next month -->
n += 1; <!-- accumulate months since Jan 1st -->
}
s = Math.floor(w / days); <!-- how many days left in those seconds -->
w -= (s * days); <!-- subtract remaining days -->
r = Math.floor(w / hours); <!-- get the number of hours -->
w -= (r * hours); <!-- subtract the hours -->
q = Math.floor(w / minutes); <!-- get the number of minutes -->
w -= (q * minutes); <!-- and subtract them -->
<!-- finally: the remaining seconds, without the microseconds -->
p = Math.floor(w / 1000);
<!-- Display the result -->
document.write("Or, more precisely:<br>");
document.write(x+" years, "+n+" months, "+s);
if (s==1) {document.write(" day, ");}
else {document.write(" days, ");}
document.write(r+" hours, "+q+" minutes, "+p+" seconds<br>");
document.write("(Those "+x+" years encompass "+z+" days.)<p>");