Java Period get year, month, day different between two LocalDate values

Description

Java Period get year, month, day different 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(2018, 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());
  }/* ww w  .  j a v  a  2  s . c o m*/
}



PreviousNext

Related