Obtain Month Name from Date in JavaScript
Determining the month name from a date object is a common task in JavaScript. Consider the following date object:
var objDate = new Date("10/11/2009");
Using the Internationalization API
With the advent of the ECMAScript Internationalization API, it is now possible to retrieve the month name with ease:
const date = new Date(2009, 10, 10); // 2009-11-10 const month = date.toLocaleString('default', { month: 'long' }); console.log(month); // "November"
This method leverages the browser's locale settings to provide the month name in the appropriate language.
Note: The toLocaleString() method is supported in modern browsers but may require a polyfill for older browsers.
The above is the detailed content of How Can I Get the Month Name from a JavaScript Date Object?. For more information, please follow other related articles on the PHP Chinese website!