JavaScript data.getFullYear() method
The date.getFullYear()
method in JavaScript returns the full year (as a four-digit number) for a specific Date
object, according to local time.
Syntax:
Returns:
- A number representing the year (e.g., 2024).
Example 1: Getting the Full Year for a Specific Date
Output:
Explanation:
- The
getFullYear()
method retrieves the full year (2024) from theDate
object for October 22, 2024.
Example 2: Getting the Current Year
Output:
Explanation:
- This retrieves the current year from the system's date and time.
Example 3: Getting the Year for an Earlier Date
Output:
Explanation:
- For the date
"1995-12-17"
, thegetFullYear()
method returns1995
.
Summary:
date.getFullYear()
returns the full four-digit year of the given date.- It is commonly used to retrieve the year for any
Date
object in JavaScript, including both past and future dates.