Java LocalDate get years between two LocalDate values

Description

Java LocalDate get years between two LocalDate values

import java.time.LocalDate;
import java.time.Month;
import java.time.temporal.ChronoUnit;

public class Main {

   public static void main(String[] args) {
      LocalDate anniversary = LocalDate.of(2000, Month.NOVEMBER, 11);
      LocalDate today = LocalDate.now();
      long yearsBetween = ChronoUnit.YEARS.between(anniversary, today);
      System.out.println("Years between dates: " + yearsBetween);

      long daysBetween = ChronoUnit.DAYS.between(anniversary, today);
      System.out.println("Days between dates:" + daysBetween);

   }/*w w  w.ja v a  2 s  .c o  m*/

}



PreviousNext

Related