// 计算结束日期
computeYmd(date, months) {
var now = new Date(date);//2022-04-15
var intYear = now.getFullYear();
var intMonth = now.getMonth() + 1; //正常的月份,
var intDay = now.getDate(); //日期
var newY = intYear;
var newM = intMonth;
var newD = intDay;
var y = parseInt(months/12);
if(y>0){
newY = newY+y;
var m = months%12;
newM = intMonth+m;
}else{
newM = intMonth+months;
}
if(newM>12){
newY = newY+1;
newM = newM-12;
}
var dMax = 31;
if(newM == 4 || newM == 6 || newM == 9 || newM == 11){
dMax =30;
}
if(newM == 2){
dMax = 28;
if (newY % 4 == 0) {
dMax = 29;
}
}
if(newD>dMax){
newD = dMax;
}
var n = newY+"-"+newM+"-"+newD
return n
},
// 使用方法,注意增加的月份需传入数字格式
this.endDate = this.computeYmd(this.startDate, Number(this.rentTime))
根据现有时间计算几个月后的时间
于 2022-11-04 16:44:58 首次发布