Find the Period between two dates - Java Date Time

Java examples for Date Time:Period

Description

Find the Period between two dates

Demo Code

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.j  a v a 2s . c om
}

Result


Related Tutorials