Q:

How to Get Month Name from a Date in JavaScript

0

How to Get Month Name from a Date in JavaScript

All Answers

need an explanation for this answer? contact us directly to get an explanation for this 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:

// 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:

// 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".

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

JavaScript / jQuery Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to Convert Decimal Values to Hexadecimal in Ja... >>
<< How to Find an Object by Property Value in an Arra...