Java Age Calculate getAge(Date birthday)

Here you can find the source of getAge(Date birthday)

Description

get Age

License

Apache License

Declaration

public static Integer getAge(Date birthday) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Calendar;
import java.util.Date;

public class Main {

    public static Integer getAge(Date birthday) {
        if (birthday == null) {
            return null;
        }//  ww w  . ja v  a  2 s  .  co m

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(birthday);
        int startY = calendar.get(Calendar.YEAR);

        calendar.setTime(new Date());
        int endY = calendar.get(Calendar.YEAR);
        int age = endY - startY;
        return age >= 0 ? age : 0;
    }
}

Related

  1. calculateAge(Date dob)
  2. calculateAgeInMonth(final Date birthDate, final Date asOfDate)
  3. calculateAgeInWeek(final Date birthDate, final Date asOfDate)
  4. getAge(Date birthDate, Date controlDate)
  5. getAge(Date birthday)
  6. getAge(Date birthday)
  7. getAge(Date birthDay)
  8. getAge(Date date)
  9. getAge(Date date, TimeZone tz)