To get the year from a date in Java, call
getYear()
.Here's how you do it:
java.util.Date date = new java.util.Date(2022, 1, 2);
int year = date.getYear();
System.out.println(year); // 2022
getYear()
.Here's how you do it:
java.util.Date date = new java.util.Date(2022, 1, 2);
int year = date.getYear();
System.out.println(year); // 2022