Java Period calculate age

Description

Java Period calculate age

import java.time.LocalDate;
import java.time.Period;

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

  public static int getAge(LocalDate date1) {
    return Period.between(date1, LocalDate.now()).getYears();
  }
}



PreviousNext

Related