Get to know MDN better
このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
setMonth() は Date インスタンスのメソッドで、現在設定されている年に基づき、指定された日時の「月」を設定します。
月を表す整数で、 0 は 1 月、 1 を 2 月、というようになります。
dateValue 省略可「日」を表す 1 から 31 までの間の整数値。
その場で Date オブジェクトを変更し、新しいタイムスタンプを返します。引数が NaN (または undefined など、 NaN に変換されるその他の値)の場合、日付は無効な日時に設定され、 NaN が返されます。
dateValue 引数を指定しなかった場合、getDate() メソッドから返される値が使われます。
指定した値が期待される日付の範囲外の場合、それに応じて setMonth() が Date オブジェクトの日付情報の更新を試みます。例えば、monthValue に 15 を指定した場合、年に 1 が加算され、月が 3 になります。
このメソッドの動作は、ある特定の月の日にちに影響を与えます。 概念上は、その月の日数を、引数として与えた新しい月の初日に加え、新しい日付を返します。 例えば、現在の値が 2016 年 1 月 31 日である場合、1 を引数として setMonth を呼び出すと 2016 年 3 月 2 日が返ってきます。 これは、2016 年の 2 月が 29 日間しかないからです。
| ECMAScript® 2027 Language Specification # sec-date.prototype.setmonth |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2025年6月18日 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.