Javascript Date isLeapYear()

Description

Javascript Date isLeapYear()


Date.prototype.isLeapYear = function() {
    var year = this.getFullYear();
    if((year & 3) != 0) return false;
    return ((year % 100) != 0 || (year % 400) == 0);
};

Javascript Date isLeapYear()

/*//  ww  w. ja v  a  2  s .co m
 * Date.isLeapYear.js
 * 
 * Copyright (c) 2012 Tomasz Jakub Rup <tomasz.rup@gmail.com>
 *
 * https://github.com/tomi77/Date.toLocaleFormat/
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */

/**
 * Checks if the year is a leap year.
 * 
 * @return true if year is a leap year; false otherwise
 */
Date.prototype.isLeapYear = function() {
 var year = this.getFullYear();
 return !(year % 4) && (year % 100) || !(year % 400);
}

Javascript Date isLeapYear()

Date.prototype.isLeapYear = function() {
    var year = this.getFullYear();
    if ((year & 3) != 0) return false;
    return ((year % 100) != 0 || (year % 400) == 0);
};

// Get Day of Year
Date.prototype.getDOY = function() {
    var dayCount = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];
    var mn = this.getMonth();
    var dn = this.getDate();
    var dayOfYear = dayCount[mn] + dn;
    if (mn > 1 && this.isLeapYear()) dayOfYear++;
    return dayOfYear;
};

onload = function() {
  var current = new Date,
      daysTill = (new Date(current.getFullYear(), 11, 25)).getDOY() - current.getDOY();

  document.getElementById('idDaysTill').innerHTML = daysTill;
};

Javascript Date isLeapYear()

Date.prototype.isLeapYear = function () { 
    var y = this.getFullYear(); 
    return (((y % 4 === 0) && (y % 100 !== 0)) || (y % 400 === 0)); 
};

Javascript Date isLeapYear()

Date.prototype.isLeapYear = function (){
    var y = this.getFullYear();
    return (y%400==0 || (y%100!=0 && y%4==0));
};



PreviousNext

Related