How to Get Month Name from a Date in JavaScript
Topic: JavaScript / jQueryPrev|Next
Answer: Use the toLocaleString()
Method
You can simply use the toLocaleString()
method to get the month name from a date in JavaScript.
This method is supported in all major modern browsers. Let's take a look at an example:
Example
Try this code »// Creating a date object
var today = new Date();
// Getting full month name (e.g. "June")
var month = today.toLocaleString('default', { month: 'long' });
console.log(month);
Similarly, you can get the month name from a date string as shown in the following example:
Example
Try this code »// Creating a date object
var today = new Date('2021-10-06'); // yyyy-mm-dd
// Getting short month name (e.g. "Oct")
var month = today.toLocaleString('default', { month: 'short' });
console.log(month);
To specify options but use the browser's default locale, use 'default'
. Possible values for month property are "numeric"
, "2-digit"
, "narrow"
, "short"
, "long"
.
Related FAQ
Here are some more FAQ related to this topic: