Java LocalDate calculate age

Description

Java LocalDate calculate age

import java.time.LocalDate;

import java.time.temporal.ChronoUnit;

public class Main {
  public static void main(String[] argv) {
    System.out.println(getAge(LocalDate.of(1976, 02, 28)));
  }/*w  w w  . j a va2 s  . c  om*/

  public static long getAge(LocalDate date) {
    return ChronoUnit.YEARS.between(date, LocalDate.now());
  }
}



PreviousNext

Related