Date.prototype.getFullYear()
getFullYear()
メソッドは、地方時に基づき、指定された日時の「年」を返します。
getYear()
メソッドの代わりに、このメソッドを使用してください。
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
構文
dateObj.getFullYear()
返値
地方時に基づき、与えた日付の年に相当する数値。
解説
getFullYear()
が返す値は絶対的な値です。1000 年から 9999 年までの日付に対して、getFullYear()
は 1995 のような 4 桁の数字を返します。2000 年以降の年について正しい値を得るには、この関数を使用してください。
例
getFullYear() の使用
以下の例は、変数 year
に今年を表す 4 桁の数字を代入します。
var today = new Date();
var year = today.getFullYear();
仕様書
ブラウザーの互換性
BCD tables only load in the browser