Sometimes, we want to get month name from two digit month number with JavaScript.
In this article, we’ll look at how to get month name from two digit month number with JavaScript.
How to get month name from two digit month number with JavaScript?
To get month name from two digit month number with JavaScript, we can use the moment.js’ format
method.
For instance, we write:
const formattedMonth = moment().month(9).format('MMMM');
console.log(formattedMonth)
We call format
with 'MMMM'
to get the full month name.
As a result, formattedMonth
is 'October'
since we called month
with 9 before calling format
.
Conclusion
To get month name from two digit month number with JavaScript, we can use the moment.js’ format
method.