Nodejs Day in Month getDaysInMonth(year, month)

Here you can find the source of getDaysInMonth(year, month)

Method Source Code

/**//from ww w . jav  a2 s .  c o m
 * Returns the amount of days in the month of the year
 * @param {int} year
 * @param {int} month
 * @return {int}
 */

Date.getDaysInMonth = function(year, month) {
  return [
    31, (Date.isLeapYear(year) ? 29 : 28),
    31, 30, 31, 30, 31, 31, 30, 31, 30, 31
  ][month];
};

Related

  1. getDaysInMonth()
    Date.prototype.getDaysInMonth = function () {
        var here = new Date(this.getTime());
        here.setDate(32);
        return 32 - here.getDate();
    };
    
  2. getDaysInMonth()
    Date.prototype.getDaysInMonth = function () {
        Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28;
        return Date.daysInMonth[this.getMonth()];
    
  3. getDaysInMonth()
    Date.prototype.getDaysInMonth = function() {
      return Date.getDaysInMonth(this.getFullYear(), this.getMonth());
    };
    
  4. getDaysInMonth()
    Date.prototype.getDaysInMonth = function ()
        return Date.getDaysInMonth(this.getFullYear(), this.getMonth());
    };
    
  5. getDaysInMonth()
    Date.prototype.getDaysInMonth = function () {
        var m = this.getMonth() + 1,
            y = this.getFullYear();
        return /8|3|5|10/.test(--m) ? 30 : m == 1 ? (!(y % 4) && y % 100) || !(y % 400) ? 29 : 28 : 31;
    };
    
  6. getDaysInMonth(year, month)
    Date.getDaysInMonth = function (year, month)
        return [31, (Date.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
    };
    
  7. getDaysInMonthOfYear()
    Date.prototype.getDaysInMonthOfYear = function(){
      month = this.getMonth();
      if(month === 1){
        return this.isLeapYear()? 29:28;
      }else{
        if(month>=8){
          return month%2? 31:30;
        }else{
          return month%2? 31:30;
    ...