Nodejs Day in Month daysInMonth()

Here you can find the source of daysInMonth()

Method Source Code

// Spanish dates//from   w w  w.j av  a 2  s  . com
dateFormat.i18n = {
   dayNames: [
      "Dom", "Lun", "Mar", "Mie", "Jue", "Vie", "Sab",
      "Domingo", "Lunes", "Jueves", "Mi?oles", "Jueves", "Viernes", "S?do"
   ],
   monthNames: [
      "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
      "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"
   ]
};

// Days in a month
Date.prototype.daysInMonth = function () {
   return new Date(this.getFullYear(), this.getMonth()+1, 0).getDate()
}

// -1 Month
Date.prototype.previousMonthDate = function() {
  previousDate = new Date(this);
  previousDate.setMonth(this.getMonth() - 1);
  return previousDate;
}

// +1 Month
Date.prototype.nextMonthDate = function() {
  nextDate = new Date(this);
  nextDate.setMonth(this.getMonth() + 1);
  return nextDate;
}

Date.prototype.isInTheSameMonth = function(date) {
  return (
    this.getMonth() == date.getMonth() &&
    this.getFullYear() == date.getFullYear()
  );
}

Related

  1. daysInMonth()
    Date.prototype.daysInMonth = function() {
        return 32 - new Date(this.getFullYear(), this.getMonth(), 32).getDate();
    };
    
  2. daysInMonth()
    Date.prototype.daysInMonth = function() {
        return 32 - new Date(this.getYear(), this.getMonth(), 32).getDate();
    };
    
  3. daysInMonth()
    Date.prototype.daysInMonth = function () {
      return new Date(this.getFullYear(), this.getMonth() + 1, 0).getDate();
    };
    
  4. getDaysInMonth()
    Date.prototype.getDaysInMonth = function () {
        var here = new Date(this.getTime());
        here.setDate(32);
        return 32 - here.getDate();
    };
    
  5. getDaysInMonth()
    Date.prototype.getDaysInMonth = function () {
        Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28;
        return Date.daysInMonth[this.getMonth()];
    
  6. getDaysInMonth()
    Date.prototype.getDaysInMonth = function() {
      return Date.getDaysInMonth(this.getFullYear(), this.getMonth());
    };