Get month name from Date in JavaScript
Question:
How to get month name from Date in JavaScript? Answer:
let now = new Date();
let monthName = now.toLocaleString('default', { month: 'long' });
console.log('The month is: ' + monthName);
Description:
The toLocaleString()
method returns a string with a language sensitive representation of this date.
The new locales and options arguments let applications specify the language whose formatting conventions should be used and customize the behavior of the function.
Reference:
toLocaleString manual
Share "How to get month name from Date in JavaScript?"
Related snippets:
- Convert milliseconds to minutes and seconds
- Check if date is valid in JavaScript
- Generate random date with JavaScript
- Generate random date in a range with JavaScript
- Check if date is today
- Get month name from Date in JavaScript
- Get the current date in JavaScript
- Get difference between 2 dates in JavaScript
- Get yesterday's date in JavaScript
- Get tomorrow's date in JavaScript
Tags:
javascript, date, month name, tolocalestring Technical term:
Get month name from Date in JavaScript