Get month name from two digit month number
While there's nothing wrong with Kevin's answer, it is probably more correct (in terms of efficiency) to obtain the month string without going through a moment
object.
var monthNum = 9; // assuming Jan = 1var monthName = moment.months(monthNum - 1); // "September"var shortName = moment.monthsShort(monthNum - 1); // "Sep"
You want to pass the month when you create the Moment object:
var formattedMonth = moment('09', 'MM').format('MMMM'); // Septembermoment( '09', // Desired month 'MM' // Tells MomentJs the number is a reference to month).format('MMMM') // Formats month as name
You need to pass the month as a number, not text - so...
var formattedMonth = moment().month(9).format('MMMM');console.log(formattedMonth)
Result:October