getMonthメソッド

メソッド getMonth は 日付オブジェクト に適用され、現在の月を返します。月の番号は0から始まります。

構文

javascript日付.getMonth();

例

現在の月の番号を出力してみましょう:

javascriptlet date = new Date();
let res = date.getMonth();

console.log(res);

例

指定された日付の月を出力してみましょう:

javascriptlet date = new Date(2025, 11, 31);
let res = date.getMonth();

console.log(res);

コードの実行結果:

javascript11

関連項目

  • メソッド getDay,
    曜日を取得します
  • メソッド getFullYear,
    年を取得します
  • メソッド getDate,
    月の日を取得します
  • メソッド getHours,
    時を取得します
  • メソッド getMinutes,
    分を取得します
  • メソッド getSeconds,
    秒を取得します