Retrieve Month Name from JavaScript Date
In JavaScript, you can access essential date information, including the month. This guide demonstrates how to obtain the month name from a given date object.
For instance, given the date object:
var objDate = new Date("10/11/2009");
Solution Using ECMAScript Internationalization API:
The ECMAScript Internationalization API provides a standardized way to format dates according to different locales. You can use it to retrieve the month name as follows:
const date = new Date(2009, 10, 10); // 2009-11-10 const month = date.toLocaleString('default', { month: 'long' }); console.log(month);
This will output "November" since the 'long' option formats the month in its full name. You can also use the 'short' option to get a shorter name, such as "Nov."
Additional Notes:
The above is the detailed content of How Can I Retrieve the Month Name from a JavaScript Date Object?. For more information, please follow other related articles on the PHP Chinese website!