Java LocalDate get Period between two LocalDate values

Description

Java LocalDate get Period between two LocalDate values

import java.time.LocalDate;
import java.time.Month;
import java.time.Period;

public class Main {

   public static void main(String[] args) {
      LocalDate anniversary = LocalDate.of(2000, Month.NOVEMBER, 11);
      LocalDate today = LocalDate.now();
      Period period = Period.between(anniversary, today);
      System.out.println("Number of Days Difference: " + period.getDays());
      System.out.println("Number of Months Difference: " + period.getMonths());
      System.out.println("Number of Years Difference: " + period.getYears());

   }//from  w ww. ja  va 2  s  . co  m

}



PreviousNext

Related