Java Age Calculate getAge(Date birthday)

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

Description

get Age

License

Open Source License

Declaration

public static int getAge(Date birthday) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static int getAge(Date birthday) {
        Calendar birthCal = Calendar.getInstance();
        birthCal.setTime(birthday);/*from   w  w  w.  j  a v a2 s.  c o  m*/
        Calendar today = Calendar.getInstance();
        int age = today.get(Calendar.YEAR) - birthCal.get(Calendar.YEAR);
        if (today.get(Calendar.DAY_OF_YEAR) < birthCal
                .get(Calendar.DAY_OF_YEAR)) {
            age--;
        }
        return age;
    }
}

Related

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