我遇到一个问题,添加块时,我创建了一个日历,我必须将明天的日期写入其中,问题是如果今天是第31天和第7个月,那么添加+1天应该算01.08,但现在添加后,它给出了 32.07。如果您告诉我如何正确操作,我将不胜感激。
addDayOff() {
let nowDate = new Date();
let date = nowDate.getDate() + 1;
let month = nowDate.getMonth() + 1;
let year = nowDate.getFullYear();
if (date <= 9) date = `0${date}`;
if (month <= 9) month = `0${month}`;
this.calendar.unshift({
startDate: `${year}-${month}-${date}`,
endDate: `${year}-${month}-${date}`,
onGoingStartDate: `${month}-${date}`,
onGoingEndDate: `${month}-${date}`,
startTime: this.ruleData.startTime,
endTime: this.ruleData.endTime,
});
},
像这样试试
该方法返回的值
getDate()是一个从 1 到 31 的整数。该方法
getMonth()根据本地时间返回指定日期的月份,月份的编号为一年中的第一个月从零开始,即从0到11该方法
getYear()返回年份减去 1900你需要小心月份