Fixing the Time
domingo, 7 de diciembre de 2008
Sin comentarios
Fixing the Time
function total(year) { var seconds = 365 * 24 * 60 * 60; //Normal Year; var plus = 24 * 60 * 60; // Leap year have one more day var leap = false; if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) leap = true; if (leap) seconds += plus; if (year == 1972) seconds += 2; if (year > 1972 && year < 1980) seconds += 1; if (year > 1980 && year < 1984) seconds += 1; if (year > 1988 && year < 1991) seconds += 1; if (year > 1991 && year < 1996) seconds += 1; if (year > 1996 && year < 1999) seconds += 1; if (year == 1985 || year == 1987 || year == 2005 || year == 2008) seconds += 1; document.write('Year: '+year+', Total of secods: '+seconds+'<br />'); } total(1972); total(1975); total(1980); total(1981); total(2004); total(2005); total(2006); total(2007); total(2008); total(2009);
Result:
Year: 1972, Total of secods: 31622402
Year: 1975, Total of secods: 31536001
Year: 1980, Total of secods: 31622400
Year: 1981, Total of secods: 31536001
Year: 2004, Total of secods: 31622400
Year: 2005, Total of secods: 31536001
Year: 2006, Total of secods: 31536000
Year: 2007, Total of secods: 31536000
Year: 2008, Total of secods: 31622401
Year: 2009, Total of secods: 31536000
Leap Second (http://en.wikipedia.org/wiki/Leap_second)
Leap Years (http://en.wikipedia.org/wiki/Leap_year)