Nodejs Year Add addYears(y)

Here you can find the source of addYears(y)

Method Source Code

Date.prototype.addYears = function(y) {
   var m = this.getMonth();
   this.setFullYear(this.getFullYear() + y);

   if (m < this.getMonth()) {
      this.setDate(0);//from   w  w  w .  j  a  v  a  2  s. c o m
   }
};

Related

  1. addYear()
    Date.prototype.addYear = function(){
      this.setFullYear(this.getFullYear() + 1);
    };
    
  2. addYear()
    'use strict';
    Date.prototype.addYear = function addYear () {
      this.setFullYear(this.getFullYear() + 1);
    };
    
  3. addYears(number)
    Date.prototype.addYears = function (number) {
        var date = new Date(this);
        date.setFullYear(date.getFullYear() + number);
        return date;
    };
    
  4. addYears(numberOfYears)
    Date.prototype.addYears = function (numberOfYears) {
        var year = this.getFullYear();
        year += parseInt(numberOfYears);
        this.setFullYear(year);
    
  5. addYears(value)
    Date.prototype.addYears = function(value) {
      var month = this.getMonth();
      this.setFullYear(this.getFullYear() + value);
      if (month < this.getMonth()) {
        this.setDate(0);
      return this;
    };
    
  6. addYears(year)
    Date.prototype.addYears = function(year){
      return new Date(this.getTime() + year*24*60*60*1000*(this.isLeapYear()?366:365));
    
  7. addYears(years)
    Date.prototype.addYears = function(years) {
      return this.addMonths(years * 12);
    };