通过年数获取最新的日期
function GetDate(year){
var date = new Date();
var newdate = new Date(date.setFullYear(date.getFullYear()+year));
var Y = newdate.getFullYear() + "-";
var M = (newdate.getMonth() + 1 < 10
? "0" + (newdate.getMonth() + 1)
: newdate.getMonth() + 1) + "-";
var D = newdate.getDate() < 10 ? "0" + newdate.getDate() : newdate.getDate();
console.log(Y + M + D);
}
通过月数获取最新的日期
function GetDate(month){
var date = new Date();
var newdate = new Date(date.setMonth(date.getMonth()+month));
var Y = newdate.getFullYear() + "-";
var M = (newdate.getMonth() + 1 < 10
? "0" + (newdate.getMonth() + 1)
: newdate.getMonth() + 1) + "-";
var D = newdate.getDate() < 10 ? "0" + newdate.getDate() : newdate.getDate();
console.log(Y + M + D);
}
通过天数获取最新的日期
function GetDate(day){
var date = new Date();
var newdate = new Date(date.setDate(date.getDate()+day));
var Y = newdate.getFullYear() + "-";
var M = (newdate.getMonth() + 1 < 10
? "0" + (newdate.getMonth() + 1)
: newdate.getMonth() + 1) + "-";
var D = newdate.getDate() < 10 ? "0" + newdate.getDate() : newdate.getDate();
console.log(Y + M + D);
}