Get the Month Name from a Date in JavaScript


Borislav Hadzhiev

Last updated: Oct 24, 2021


Photo from Unsplash

Get the Name of a Month from a Date #

To get the name of a month from a date:

  1. Create a date object using the new Date() constructor.
  2. Call the toLocaleString() method on the date object, setting the month property in the options object.
  3. The toLocaleString() method will return the name of the month.
// 👇️ February 24th const date = new Date(2025, 01, 24); const nameOfMonth = date.toLocaleString('default', { month: 'long', }); console.log(nameOfMonth); // 👉️ February

We created a Date object, using the new Date() constructor.

The parameters we passed to the Date method are the year, month and day.

Month indexes are zero-based in JavaScript, meaning January is 0 and December is 11.

The next step is to call the toLocaleString method on the Date object, passing it the following parameters.

  1. the locale - in which language the name of the month should be returned. By specifying default, it can vary based on the user's browser preferences.
  2. the options object - we set the month setting to long to get the full name of the month. Other possible values are short and narrow.

If you want to get the month's name in a different locale, pass the locale as the first parameter to the method.

const date = new Date(2025, 01, 24); const nameOfMonthUS = date.toLocaleString('en-US', { month: 'long', }); console.log(nameOfMonthUS); // 👉️ February const nameOfMonthDE = date.toLocaleString('de-DE', { month: 'long', }); console.log(nameOfMonthDE); // 👉️ Februar

If you need to get the month's name in a different format, e.g. the first 3 letters, or only the first letter, update the value of the month property in the options object.

// 👇️ February console.log(date.toLocaleString('en-US', {month: 'long'})); // 👇️ Feb console.log(date.toLocaleString('en-US', {month: 'short'})); // 👇️ F console.log(date.toLocaleString('en-US', {month: 'narrow'}));

Setting the month to long, gives us the entire name of the month. The short value gives us the first 3 letters of the month, and narrow - just the first letter.

Further Reading #

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.