Date.prototype.getMonth()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

getMonth() メソッドは、地方時に基づき、指定された日付の「月」を表す 0 を基点とした値(すなわち 0 が年の最初の月を示す)を返します。

試してみましょう

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

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

構文

js
getMonth()

返値

地方時に基づき、与えた日付の「月」を表す 0 から 11 までの間の整数値。0 は 1 月、1 は 2 月、11 は 12 月に対応します。

getMonth() の使用

以下の 2 行目の文は、Date オブジェクトである xmas95 の値に基づき、変数 month に 11 という値を代入します。

js
const xmas95 = new Date("December 25, 1995 23:15:30");
const month = xmas95.getMonth();

console.log(month); // 11

メモ: 必要に応じて、月の完全な名前(例えば January )は Intl.DateTimeFormat()options 引数を付けることで取得することができます。このメソッドを使用すれば、国際化がより簡単になります。

js
const options = { month: "long" };
console.log(new Intl.DateTimeFormat("en-US", options).format(Xmas95));
// December
console.log(new Intl.DateTimeFormat("de-DE", options).format(Xmas95));
// Dezember

仕様書

Specification
ECMAScript® 2025 Language Specification
# sec-date.prototype.getmonth

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
getMonth

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報