JavaScriptの日付setFullYear()
例1
const d = new Date();
d.setFullYear(2020);
定義と使用法
setFullYear()
日付の年を設定します。
setFullYear()
月日を設定することもできます。
例2
const d = new Date();
d.setFullYear(2020, 10, 3);
例3
日付を6か月前に設定します:
const d = new Date();
d.setFullYear(d.getFullYear(), d.getMonth() - 6);
ブラウザのサポート
setFullYear()
ECMAScript1(ES1)機能です。
ES1(JavaScript 1997)は、すべてのブラウザーで完全にサポートされています。
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
構文
Date.setFullYear(year, month, day)
パラメーター
year | Required. The year. Negative values are allowed. |
month | Optional. The month (0 to 11). Higher and lower values are handeled with date maths:
|
day | Optional. The day (0 to 31). Higher and lower values are handeled with date maths:
|
戻り値
数。 日付から1970年1月1日00:00:00UTCまでのミリ秒数。 |