Get Previous/Next Month, Previous/Next Year - Node.js Date

Node.js examples for Date:Month

Description

Get Previous/Next Month, Previous/Next Year

Demo Code

def.setPrevMonth = function() {
    var d = new Date();
    d.setTime(this.value.getTime());//from w w w .j  ava 2s  . co  m
    d.setMonth(d.getMonth() - 1);
    this.setDate(d);
};

def.setNextMonth = function() {
    var d = new Date();
    d.setTime(this.value.getTime());
    d.setMonth(d.getMonth() + 1);
    this.setDate(d);
};

def.setPrevYear = function() {
    var d = new Date();
    d.setTime(this.value.getTime());
    d.setFullYear(d.getFullYear() - 1);
    this.setDate(d);
};

def.setNextYear = function() {
    var d = new Date();
    d.setTime(this.value.getTime());
    d.setFullYear(d.getFullYear() + 1);
    this.setDate(d);
};

def.setYear = function(y) {
    var d = new Date();
    d.setTime(this.value.getTime());
    d.setFullYear(y);
    this.setDate(d);
};

Related Tutorials