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.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.