Categories
JavaScript Answers

How to use moment.js and JavaScript to get number of days in current month?

Spread the love

Sometimes, we want to use moment.js and JavaScript to get number of days in current month.

In this article, we’ll look at how to use moment.js and JavaScript to get number of days in current month.

How to use moment.js and JavaScript to get number of days in current month?

To use moment.js and JavaScript to get number of days in current month, we can use the daysInMonth method.

For instance, we write

const numDaysInMonth = moment("2022-02", "YYYY-MM").daysInMonth();

to call daysInMonth on a moment object with the year and month to get the number of days in a month.

Conclusion

To use moment.js and JavaScript to get number of days in current month, we can use the daysInMonth 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 *