DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Date.isleap

09.15.2005
| 3642 views |
  • submit to reddit
        
Date.isleap = function(year){
 return ((year % 400) == 0) ? 1 :
        ((year % 100) == 0) ? 0 :
        ((year % 4)   == 0) ? 1 :
         0;
}
Date.prototype.isleap = function(){
    return Date.isleap(this.getFullYear())
}
// isleap current year
new Date().isleap()
    

Comments

Snippets Manager replied on Sun, 2010/11/28 - 3:08am

Check out this library for Date manipulation: http://plugins.jquery.com/project/fIsForFormat I'm fairly certain that leap year detection is one of its features. (I primarily use it for date formatting.) I have no idea why it is listed as a jQuery plugin - as far as I can tell it doesn't reference any other libraries.