faqts : Computers : Programming : Languages : JavaScript : Language Core : Dates

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

61 of 71 people (86%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

How can I check whether a year is a leap year?

May 10th, 2001 10:00
jsWalter, Martin Honnen,


A leap year is
  divisible by 4 and (not divisible by 100 or divisible by 400)
So to check that use a JavaScript function alike
  function isLeapYear (year) {
    return (year % 4 == 0) && 
           ((year % 100 != 0) || (year % 400 == 0));
  }
Examples:
  alert(isLeapYear(2000))
  alert(isLeapYear(1999))
wt 5/10/01
I have a collection of methods that extend the Date Object.
One of them solves this problem.
ww.torres.ws/javascript
Walter