【问题标题】:Get current month in Eleventy using Nunjucks?使用 Nunjucks 获取 Eleventy 的当前月份?
【发布时间】:2021-11-24 15:41:35
【问题描述】:

只是想用简码获取 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;
    })

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

【问题讨论】:

标签: javascript date nunjucks eleventy jamstack


【解决方案1】:

这种方式比较容易。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多