JavaScriptの日付setUTCFullYear()
例
年を2015年に設定します。
const d = new Date();
d.setUTCFullYear(2015);
以下の「自分で試してみてください」の例をもっと見てください。
定義と使用法
setUTCFullYear()メソッドは、UTCに従って日付オブジェクトの年を設定します。
ノート
UTC(協定世界時)は、世界時間標準によって設定された時間です。
UTC時間はGMT時間(グリニッジ標準時)と同じです。
ブラウザのサポート
setUTCFullYear()
ECMAScript1(ES1)機能です。
ES1(JavaScript 1997)は、すべてのブラウザーで完全にサポートされています。
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
構文
Date.setUTCFullYear(year, month, day)
パラメータ値
Parameter | Description |
---|---|
year | Required. A value representing the year, negative values are allowed |
month | Optional. An integer representing the month
Expected values are 0-11, but other values are allowed:
|
day | Optional. An integer representing the day of month
Expected values are 1-31, but other values are allowed:
If the month has 31 days:
If the month has 30 days:
|
戻り値
Type | Description |
---|---|
Number | Milliseconds between the date object and midnight January 1 1970 |
技術的な詳細
JavaScriptバージョン: | ECMAScript 1 |
---|
その他の例
例2
日付を2020年11月3日、UTC時間に設定します。
const d = new Date();
d.setUTCFullYear(2020, 10, 3);
例
日付を6か月前、UTC時間に設定します。
const d = new Date();
d.setUTCFullYear(d.getUTCFullYear, d.getUTCMonth() - 6);