Java Period get period between two LocalDate values

Description

Java Period 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());

   }// www  . j  a  va2  s  . c o m

}



PreviousNext

Related