-addM(index,date){
//index 加几个月
//date 从哪天开始加
let currentDate
if(date){
currentDate = new Date(date);
}else{
currentDate = new Date();
}
var futureDate = new Date(currentDate.getFullYear(), currentDate.getMonth() + index, currentDate.getDate());
// 检查是否超出当月天数,如果超出则设置为当月最后一天
futureDate.setDate(Math.min(futureDate.getDate(), new Date(futureDate.getFullYear(), futureDate.getMonth() + 1, 0).getDate()));
// 将结果格式化为字符串
var formattedDate = futureDate.toISOString().split('T')[0];
console.log('个月后的日期:', formattedDate);
return formattedDate
},
在当前时间或指定时间的基础上加几个月
最新推荐文章于 2024-10-10 09:56:47 发布