Do you want to get the name of the month (e.g: Oct/October) from the date object in JavaScript?
It is now possible to do this with the ECMAScript Internationalization API.
In this blog post, we will learn how we can use the full name of the current month or get the full name of the month from any date in javascript.
Get Current Month Name From Date In Javascript
In the previous blog post we saw how we can get the Current Month In Javascript.
We use the ECMAScript Internationalization API to get the long name, short name and narrow name for the month.
Let's see this in an example.
Example:
Result:
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 toLocaleString() method and provided the locales and options to it.
This gives us the current month name in javascript.
Get Month Name From Any Date In Javascript
In the last example, we saw how we could get the current month name from the current date.
But what if you want to get the month name from any date in javascript?
In the following example, we will learn that because the method .toLocaleString() is on the date object, you can pass in a date of your choice.
Example:
Result: