获取本月往后一年的日期月份信息
作者:互联网
let year = new Date().getFullYear() let month = new Date().getMonth() + 1; let time = '' let itemObj={}; let timeArr=[]; for (let i = 1; i <= 12; i++) { time = `${year}-${month}`; if (month >= 12) { year++; month = 1; } else { month++; } itemObj={text:time}; timeArr.push(itemObj); } console.log(JSON.stringify(timeArr));
输出:
[{"text":"2021-9"},{"text":"2021-10"},{"text":"2021-11"},{"text":"2021-12"},{"text":"2022-1"},{"text":"2022-2"},{"text":"2022-3"},{"text":"2022-4"},{"text":"2022-5"},{"text":"2022-6"},{"text":"2022-7"},{"text":"2022-8"}]
标签:text,往后,month,获取,日期,let,2021,2022,timeArr 来源: https://www.cnblogs.com/llcdbk/p/15247773.html