Home > Web Front-end > JS Tutorial > How Can I Get the Month Name from a JavaScript Date Object?

How Can I Get the Month Name from a JavaScript Date Object?

Susan Sarandon
Release: 2024-12-13 19:52:11
Original
696 people have browsed it

How Can I Get the Month Name from a JavaScript Date Object?

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");
Copy after login

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"
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template