A RetroSearch Logo

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

Search Query:

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

Date.prototype.getMonth() - JavaScript | MDN

Date.prototype.getMonth()

Baseline Widely available

getMinutes() は Date インスタンスのメソッドで、この日付の「月」を表す 0 を基点とした値(すなわち 0 が年の最初の月を示す)を返します。

試してみましょう
const moonLanding = new Date("July 20, 69 00:20:18");

console.log(moonLanding.getMonth()); // (January gives 0)
// 予想される結果: 6
構文 引数

なし。

返値

地方時に基づき、指定された日時の「月」を表す 0 から 11 までの間の整数値です。 1 月は 0、2 月 は 1 というようになります。日時が無効な場合は NaN を返します。

解説

getMonth() の返値は 0 から始まるため、例えば、月の配列のインデックス指定に有益です。

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

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

ただし、国際化のためには、代わりに Intl.DateTimeFormat を options 引数付きで使用することをお勧めします。

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"
例 getMonth() の使用

変数 month には、 Date オブジェクト xmas95 に基づいて、 11 という値が入ります。

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

console.log(month); // 11
仕様書 ブラウザーの互換性 関連情報

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