Find years and days between two dates - Java Date Time

Java examples for Date Time:Local Date Time

Description

Find years and days between two dates

Demo Code

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 ww . j  a va2s  .  com
}

Result


Related Tutorials