Categories
JavaScript Answers

How to get month name from two digit month number with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *