Thanks to visit codestin.com
Credit goes to coreui.io

How to get the current month in JavaScript

Getting the current month is crucial for date filtering, monthly reports, and seasonal functionality in web applications. As the creator of CoreUI, a widely used open-source UI library, I’ve implemented month extraction in numerous calendar components, analytics dashboards, and date picker widgets. From my expertise, the most important consideration is understanding that getMonth() returns zero-based values (0-11). This method requires careful handling to match standard month numbering expectations in user interfaces.

Use getMonth() method to get the current month, remembering it returns 0-11.

const currentMonth = new Date().getMonth() + 1

The getMonth() method returns the month as a zero-based index where January is 0, February is 1, and so on through December as 11. For standard month numbering (1-12), add 1 to the result: getMonth() + 1. This zero-based system is consistent with JavaScript’s Date constructor but differs from human-readable month numbers. When displaying months to users, either add 1 for numeric display or use month name arrays for text representation.

Best Practice Note:

This is the same approach we use in CoreUI components for month-based filtering and calendar navigation. Always remember the zero-based indexing - a common source of off-by-one errors is forgetting to add 1 when displaying month numbers to users.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author

Subscribe to our newsletter
Get early information about new products, product updates and blog posts.
How to loop through a 2D array in JavaScript
How to loop through a 2D array in JavaScript

How to Merge Objects in JavaScript
How to Merge Objects in JavaScript

How to Use Bootstrap Modal in Vue 3 – Clean Integration with CoreUI
How to Use Bootstrap Modal in Vue 3 – Clean Integration with CoreUI

The Best Bootstrap Alternative for Developers in 2025
The Best Bootstrap Alternative for Developers in 2025

Answers by CoreUI Core Team