js addDays ,addYears

//添加天
Date.prototype.addDays = function (d) {
    this.setDate(this.getDate() + d);
};

//添加周
Date.prototype.addWeeks = function (w) {
    this.addDays(w * 7);
};

//添加月
Date.prototype.addMonths = function (m) {
    var d = this.getDate();
    this.setMonth(this.getMonth() + m);

    if (this.getDate() < d)
        this.setDate(0);
};
//添加年
Date.prototype.addYears = function (y) {
    var m = this.getMonth();
    this.setFullYear(this.getFullYear() + y);

    if (m < this.getMonth()) {
        this.setDate(0);
    }
};
原文地址:https://www.cnblogs.com/xuguanghui/p/7793226.html