1.获取该日期(xxxx年xx月xx日)在本月的所有之前的日期,即xx月01日-xx月xx日;
2.获取该日期(xxxx年xx月xx日)上月自xx日起至月末的日期。
getLastMonthDays(date) {
//该日期的日
let theDay = new Date(date).getDate();
//获取该日期的上一个月
let lastMon = new Date(new Date(date).getTime);
lastMon.setMonth(lastMon.getMonth());
lastMon.setDate(0);
//上一个月的月末日期
let lastDayOfLastMon = lastMon.getDate();
//该日期上一个月的起起始日期
lastMon.setDate(theDay > lastDayOfLastMon ? lastDayOfLastMon : theDay);
let day = new Date(lastMon).getDate();//日
let month = new Date(lastMon).getMonth + 1;
month = month < 10 ? `0${Month}` : month.toString();
let arr = [];
//上个月的所有日期
if(day <= lastDayOfLastMon) {
for(let i = day; i <= lastDayOfLastMon; i++) {
let latsDate = month + (i < 10 ? "0" + i : i.toString())
arr.push(latsDate)
}
}
//本月的所有日期
for(let j = 1; j <= theDay; j++) {
let theMonth = new Date(date).getMonth + 1;
theMonth = theMonth < 10 ? `0${theMonth}` : theMonth.toString();
let theDate = theMonth + (j < 10 ? "0" + j : j.toString());
arr.push(theDate);
}
return arr;
}