//返回半年或者一年的月份
export function getRecentMonth(n) {
let nowDate = new Date()
let array = []
let year = nowDate.getFullYear()
let mon = nowDate.getMonth() + 1
for (let i = 0; i < n; i++) {
mon = mon - 1
if (mon <= 0) {
year = year - 1
mon = mon + 12
}
if (mon < 10) {
mon = '0' + mon
}
array[i] = year + '-' + mon
}
return array
}
- 使用getRecentMonth(6)