Tuesday, November 28, 2006

[Script] How to estimate the amount of day in February?

To implement this function, you should understand when February has 29 days.
February has 29 days in any year evenly divisible by four, EXCEPT for centurial years which are not also divisible by 400.

After you understand the definition, the implement will become very easy:

function daysInFebruary (year){
return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

0 Comments:

Post a Comment

<< Home