Javascript Date daysInMonth()

Description

Javascript Date daysInMonth()


Date.prototype.daysInMonth = function() {
    return 32 - new Date(this.getFullYear(), this.getMonth(), 32).getDate();
};

Javascript Date daysInMonth()

Date.prototype.daysInMonth = function (){
    var x = 31;//  w ww  .j a v  a  2s  . co  m
    switch (this.getMonth()) //zero-index
    {
     case 1:  x = (this.isLeapYear()? 29 : 28);break;
     case 3:
     case 5:
     case 8:
     case 10: x = 30;
    }
    return x;
};



PreviousNext

Related