Get Current Month In Javascript using .getMonth() Method

Sameer Saini May 04, 2022
Get Current Month In Javascript using .getMonth() Method

Do you want to get the current Month of the year in your HTML website?

If that's the case, you might be in luck as javascript offers a really easy way to get the current month from the date.

In this blog post, we will learn how we can use the Date object and get the current month in javascript.



Javascript Current Month - getMonth() Method Explained

If you want to show the current month dynamically in your HTML website, you will have to make use of javascript's date object.

This date object get's the current date of the client machine the browser is running under.

Using this Date() object, we can get the current month using the getMonth() method

Let's see this in an example and get the current month in javascript at the time of writing this article.





Get current month in javascript


From the example, we can see that we used created a new constant called dateToday and we assigned it the new Date().

From the dateToday, we used the getMonth() method and extracted the month from today's date.

This gives us the current month as a number.