/** * @author lautturi.com * Java example: how to get number of years between two dates in java */ import java.util.*; import java.time.LocalDate; import java.time.Month; import java.time.temporal.*; public class Lautturi { public static void main(String[] args){ LocalDate birthday = LocalDate.parse("2000-10-13"); LocalDate now = LocalDate.now(); long diff = ChronoUnit.YEARS.between(birthday, now); System.out.println("The age is: " + diff); } }
output:
The age is: 19