The number of days in a year depends on whether it is a leap year or not.
ECMA compliant implementations use an extended Gregorian system to map a day number to a year number and to determine the month and date within that year. In this system, leap years are summarized thus:
DaysInYear(y) =
365 if ((y modulo 4) != 0)
366 if ((y modulo 4) == 0) and ((y modulo 100) != 0)
365 if ((y modulo 4) == 0) and ((y modulo 400) != 0)
366 if ((y modulo 400) == 0)
// Test number of days in year
document.write("<TABLE BORDER=1>");
for(var ii=1980; ii<2009; ii++)
{
document.write("<TR>");
document.write("<TD>");
document.write(ii);
document.write("</TD>");
document.write("<TD>");
document.write(daysInYear(ii));
document.write("</TD>");
document.write("</TR>");
}
document.write("</TABLE>");
// Day from year function
function daysInYear(aYear)
{
if((aYear % 4) != 0)
{
return 365;
}
if(((aYear % 100) != 0) ||
((aYear % 400) == 0))
{
return 366;
}
return 365;
}| See also: | Broken down time, Day from year, In leap year, Time range, Year number |
| Prev | Home | Next |
| Daylight savings time adjustment | Up | DbPool object |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. | ||