Date.prototype.getFullYear()
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.
getFullYear()
メソッドは、地方時に基づき、指定された日時の年を返します。
getYear()
メソッドの代わりに、このメソッドを使用してください。
試してみましょう
構文
js
getFullYear()
返値
地方時に基づき、与えた日付の年に相当する数値。
解説
getFullYear()
が返す値は絶対的な値です。1000 年から 9999 年までの日付に対して、getFullYear()
は 1995 のような 4 桁の数字を返します。 2000 年以降の年について正しい値を得るには、この関数を使用してください。
例
getFullYear() の使用
以下の例は、変数 year
に今年を表す 4 桁の数字を代入します。
js
const today = new Date();
const year = today.getFullYear();
仕様書
Specification |
---|
ECMAScript® 2025 Language Specification # sec-date.prototype.getfullyear |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
getFullYear |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.