DEV Community

Discussion on: How to get month list in your locale

 
dannyengelman profile image
Danny Engelman • Edited

And since year is not a parameter, no need for const year declaration to get a monthname

new Date(0, monthIndex) will do, for ES Arrow function:

const getMonthList = (locale = "en", notation = "long" ) =>
  Array.from(
    Array(12).keys(),
    key => Intl.DateTimeFormat(locale, {
      month: {
         s : "short",
         n : "numeric"
      } [notation[0]] || "long"
    })
    .format(new Date(0, key))
  );
```

`
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
pretaporter profile image
Maksim

Cool, thanks!

For constructor of Intl.DateTimeFormat locales is optional param. No requirement to provide default value of locale.