Date.prototype.setUTCMonth()

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.

setUTCMonth() メソッドは、協定世界時に基づき、指定された日時の「月」を設定します。

試してみましょう

const event = new Date("December 31, 1975 23:15:30 GMT-3:00");

console.log(event.toUTCString());
// Expected output: "Thu, 01 Jan 1976 02:15:30 GMT"

console.log(event.getUTCMonth());
// Expected output: 0

event.setUTCMonth(11);

console.log(event.toUTCString());
// Expected output: "Wed, 01 Dec 1976 02:15:30 GMT"

構文

js
setUTCMonth(monthValue)
setUTCMonth(monthValue, dayValue)

引数

monthValue

1 月から 12 月を表す 0 から 11 までの間の整数値。

dayValue

任意。「日」を表す 1 から 31 までの間の整数値。

返値

協定世界時 (UTC) 1970 年 1 月 1 日 00:00:00 から更新された日時までの間のミリ秒単位の数値。

解説

dayValue 引数を指定しない場合、getUTCDate() メソッドから返される値が使われます。

指定した値が期待される日時の範囲外の場合、それに応じて setUTCMonth()Date オブジェクトの日付情報の更新を試みます。例えば、monthValue に 15 を指定した場合、年に 1 が加算され、月が 3 になります。

setUTCMonth() の使用

js
const theBigDay = new Date();
theBigDay.setUTCMonth(11);

仕様書

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

ブラウザーの互換性

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
setUTCMonth

Legend

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

Full support
Full support

関連情報