因此,我想得到本月和未来12个月的香草js。例如,在写这个问题的时候是2022年4月,所以我希望有这样的输出:
2022年8月2022年10月2022年11月2022年2月2023月2023 2023 2023
发布于 2022-04-18 20:53:56
for (let i = 0; i < 13; i++) {
let month = new Date().getMonth() + 1 + i;
let year = new Date().getFullYear();
if (month > 12) {
month = month - 12;
year = year + 1;
}
const nameMonth = {
1: "Jan",
2: "Feb",
3: "Mar",
4: "Apr",
5: "May",
6: "Jun",
7: "Jul",
8: "Aug",
9: "Sep",
10: "Oct",
11: "Nov",
12: "Dec",
};
console.log(year + " Year " + nameMonth[month] + " Month ");
}发布于 2022-04-18 20:58:48
for (let i = 0; i < 13; i++) {
let month = new Date().getMonth() + 1 + i;
let year = new Date().getFullYear();
if (month > 12) {
month = month - 12;
year = year + 1;
}
const nameMonth = {
1: "Jan",
2: "Feb",
3: "Mar",
4: "Apr",
5: "May",
6: "Jun",
7: "Jul",
8: "Aug",
9: "Sep",
10: "Oct",
11: "Nov",
12: "Dec",
};
console.log(
year + " Year " + nameMonth[month] + " Month "
);
}https://stackoverflow.com/questions/71916813
复制相似问题