A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth below:

Date.prototype.getMonth() - JavaScript | MDN

Date.prototype.getMonth()

Baseline Widely available

Die getMonth()-Methode von Date-Instanzen gibt den Monat für dieses Datum gemäß der lokalen Zeit als nullbasierter Wert zurück (wobei null den ersten Monat des Jahres angibt).

Probieren Sie es aus
const moonLanding = new Date("July 20, 69 00:20:18");

console.log(moonLanding.getMonth()); // (January gives 0)
// Expected output: 6
Syntax Parameter

Keine.

Rückgabewert

Eine ganze Zahl zwischen 0 und 11, die den Monat für das angegebene Datum gemäß der lokalen Zeit darstellt: 0 für Januar, 1 für Februar usw. Gibt NaN zurück, wenn das Datum ungültig ist.

Beschreibung

Der Rückgabewert von getMonth() ist nullbasiert, was nützlich ist, um in Arrays von Monaten zu indizieren, zum Beispiel:

const valentines = new Date("1995-02-14");
const month = valentines.getMonth();
const monthNames = ["January", "February", "March" /* , … */];

console.log(monthNames[month]); // "February"

Für den Zweck der Internationalisierung sollten Sie jedoch bevorzugt Intl.DateTimeFormat mit dem options-Parameter verwenden.

const options = { month: "long" };
console.log(new Intl.DateTimeFormat("en-US", options).format(valentines));
// "February"
console.log(new Intl.DateTimeFormat("de-DE", options).format(valentines));
// "Februar"
Beispiele Verwendung von getMonth()

Die Variable month hat den Wert 11, basierend auf dem Wert des Date-Objekts xmas95.

const xmas95 = new Date("1995-12-25T23:15:30");
const month = xmas95.getMonth();

console.log(month); // 11
Spezifikationen Browser-Kompatibilität Siehe auch MDN-Feedback-Box War diese Übersetzung hilfreich?

Diese Seite wurde automatisch aus dem Englischen übersetzt.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4