1

只是想用简码在 Eleventy 中获取当前月份,但遇到了一些麻烦。

这是我所在的位置:

config.addShortcode("month", () => {
let d = new Date();
let month = new Array();
month[0] = "January";
month[1] = "February";
month[2] = "March";
month[3] = "April";
month[4] = "May";
month[5] = "June";
month[6] = "July";
month[7] = "August";
month[8] = "September";
month[9] = "October";
month[10] = "November";
month[11] = "December";
var n = month[d.getMonth()]; 

return n;
    })

非常感谢所有回复,谢谢:)

4

1 回答 1

1

这种方式比较容易。

const currentMonth = (new Date()).toLocaleString('en-US', {month: 'long'});
console.log(currentMonth);

于 2021-10-04T07:19:20.667 回答