Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

get days in leap year javascript

You can find the number of days using the simple leap year algorithem:
In the Gregorian calendar three criteria must be taken into account to identify 
leap years: The year can be evenly divided by 4; If the year can be evenly 
divided by 100, it is NOT a leap year, unless; The year is also evenly divisible
by 400. Then it is a leap year.
function daysInYear(year) {
    return ((year % 4 === 0 && year % 100 > 0) || year %400 == 0) ? 366 : 365;
}
console.log(daysInYear(2016));
console.log(daysInYear(2017));
 
PREVIOUS NEXT
Tagged: #days #leap #year #javascript
ADD COMMENT
Topic
Name
4+2 =