TL; DR
Period.between( LocalDate.of( Integer.parseInt( β¦ ) , β¦ , β¦ ) , // ( year, month, dayOfMonth ) LocalDate.now( ZoneId.of( "Pacific/Auckland" ) ) ).getYears()
More details
You are using the nasty old time and time classes, now obsolete, superseded by the java.time classes.
The LocalDate class represents a date value only without time and without a time zone.
Unlike the old classes, the months have normal numbering, 1-12 for January-December.
LocalDate localDate = LocalDate.of( Integer.parseInt( β¦ ) , β¦ , β¦ ) ; // year , month , day
The time zone is critical for determining the date. At any given moment, the date changes around the world by zone. For example, a few minutes after midnight in Paris, France is a new day, still "yesterday" in Montreal Quebec .
Specify the time zone name in continent/region format, such as America/Montreal , Africa/Casablanca or Pacific/Auckland . Never use an abbreviation of 3-4 characters, for example, EST or IST , as they are not real time zones, and are not standardized or even unique (!).
ZoneId z = ZoneId.of( "America/Montreal" ); LocalDate today = LocalDate.now( z );
Representation of the time interval in the details of days-months-years is performed using the Period class.
Period age = Period.between( localDate , today );
To get a string in the standard ISO 8601 format , call age.toString() . Or interrogate for each piece, years, months, days.
int y = age.getYears(); int m = age.getMonths(); int d = age.getDays();
About java.time
The java.time framework is built into Java 8 and later. These classes supersede the nasty old legacy time classes such as java.util.Date , Calendar and SimpleDateFormat .
The Joda-Time project, now in maintenance mode , we recommend switching to the java.time classes.
To learn more, see the Oracle Tutorial . And search for qaru for many examples and explanations. JSR 310 specification .
Where to get java.time classes?
The ThreeTen-Extra project extends java.time with additional classes. This project is proof of possible future additions to java.time. Here you can find useful classes such as Interval , YearWeek , YearQuarter and more .