I want to get all months name from year in moment.js
if the year is 2011
, then i want to all months name in momentjs
i have tried this below
It's 2019 and you shouldn't be using moment.js anymore, since the vanilla Date()
class has everything we need. Except for this little bit of functionality.
Here's what I use: There's the months NPM module which has all months in different languages. It's about 991 bytes gzipped.
Example with proper import
syntax:
import months from 'months'
console.log(months.de)
Result:
[
"Januar",
"Februar",
"März",
"April",
"Mai",
"Juni",
"Juli",
"August",
"September",
"Oktober",
"November",
"Dezember"
]
If you want to list month names in a select in React:
<select
value={value}
onChange={handleChange}>
{moment.months().map(item => (
<option key={item}>{item}</option>
))}
</select>
Using moment.js you have the following methods:
moment.months() // long names
returns:
[ 'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December' ]
and
moment.monthsShort() // short names
returns:
["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]