Java Age Calculate getAge(Date birthday)

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

Description

get Age

License

Apache License

Declaration

private static float 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 {
    private static float getAge(Date birthday) {
        Calendar calendar = Calendar.getInstance();
        int yearNow = calendar.get(Calendar.YEAR);
        int monthNow = calendar.get(Calendar.MONTH);
        calendar.setTime(birthday);//from  w  ww  .  j  av  a 2s  .  c  om
        int yearBorn = calendar.get(Calendar.YEAR);
        int monthBorn = calendar.get(Calendar.MONTH);

        int year = yearNow - yearBorn;
        if (year >= 1)
            return year;

        int month = monthNow - monthBorn;
        if (month > 0 && month < 1)
            month = 1;
        return month / 12.0F;
    }
}

Related

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