Java LocalDate getYear() Method
Example
Get the year of a date:
import java.time.LocalDate;
public class Main {
public static void main(String[] args) {
LocalDate myDate = LocalDate.of(2026, 1, 15);
System.out.println(myDate.getYear());
}
}
Definition and Usage
The getYear() method returns the year of the date, as an int.
Tip: Use getMonthValue() to get the month, and getDayOfMonth() to get the day.
Syntax
public int getYear()
Parameter Values
None.
Technical Details
| Returns: | The year, for example 2026. |
|---|
Related Pages
❮ Date and Time Methods