Nodejs Year Add addYears(years)

Here you can find the source of addYears(years)

Method Source Code

/**//  w  ww . j  ava  2s  .  co m
 * Add years amount of years to the current date
 * @param {int} years
 * @return {Date}
 */

Date.prototype.addYears = function(years) {
  return this.addMonths(years * 12);
};

Related

  1. addYears(number)
    Date.prototype.addYears = function (number) {
        var date = new Date(this);
        date.setFullYear(date.getFullYear() + number);
        return date;
    };
    
  2. addYears(numberOfYears)
    Date.prototype.addYears = function (numberOfYears) {
        var year = this.getFullYear();
        year += parseInt(numberOfYears);
        this.setFullYear(year);
    
  3. 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;
    };
    
  4. addYears(y)
    Date.prototype.addYears = function(y) {
      var m = this.getMonth();
      this.setFullYear(this.getFullYear() + y);
      if (m < this.getMonth()) {
        this.setDate(0);
    };
    
  5. addYears(year)
    Date.prototype.addYears = function(year){
      return new Date(this.getTime() + year*24*60*60*1000*(this.isLeapYear()?366:365));