1

Just trying to get the current month in Eleventy with a shortcode but having a bit of trouble.

Here's where I'm at:

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;
    })

All responses are very much appreciated, thank you :)

kuwts
  • 41
  • 2
  • [`() => new Date().toLocaleString("en-US", { month: "long" })`](//developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString). Also, what is your question? – Sebastian Simon Oct 04 '21 at 07:17

1 Answers1

1

This way is easier.

const currentMonth = (new Date()).toLocaleString('en-US', {month: 'long'});
console.log(currentMonth);
Tuan Dao
  • 2,647
  • 1
  • 10
  • 20