Getting the month number by month name with Moment.js

To use simple month number try this:

const month = 2 //Feb
moment(month, 'M').format('MMMM');

Try :

moment().month("July").format("M");

Relevant documentation: http://momentjs.com/docs/#/get-set/month/

alert(moment().month("July").format("M"));
<script src="https://momentjs.com/downloads/moment.min.js"></script>

Anybody looking to get month name from month number then you can try :

const number = 1; // 0 = Jan & 11 = Dec
moment().month(number).format("MMM"); // Feb

Use following to get full month name :

const number = 1; // 0 = January & 11 = December
moment().month(number).format("MMMM"); // February

Tags:

Momentjs