Get the Month Name from a Date in JavaScript

avatar

Borislav Hadzhiev

Sun Oct 24 20212 min read

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.
index.js
// ๐Ÿ‘‡๏ธ 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.

index.js
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.

index.js
// ๐Ÿ‘‡๏ธ 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 #

Join my newsletter

I'll send you 1 email a week with links to all of the articles I've written that week

Buy Me A Coffee