let date = new Date('2023-12-28'); //当前日期
let startYear = date.getFullYear(); // 年
let startMonth = date.getMonth() + 1; // 月
年
let addYear = 3;
date.setFullYear(startYear + Number(addYear ));
endDate = this.formatDate(date);
月
let addMonth = 3;
let endMonth = startMonth + Number(addMonth );
date.setMonth(endMonth - 1);
endDate = this.formatDate(date);
日
let startTimestamp = Date.parse(date); // 转换成时间戳
一天的时间戳为86400000
let addDate = 3;
endDate = this.formatDate(
? ? new Date(
? ? ? ? startTimestamp + Number(addDate) * 86400000
? ? ?)
);
日期转换成指定格式的字符串yyyy-MM-dd
formatDate(date) {
? ? ? let dateStr = date.getFullYear() + "-";
? ? ? dateStr += date.getMonth() + 1 + "-";
? ? ? dateStr += date.getDate();
? ? ? return dateStr;
}