Java Utililty Methods Age Calculate

List of utility methods to do Age Calculate

Description

The list of methods to do Age Calculate are organized into topic(s).

Method

intgetAge(Date date, TimeZone tz)
get Age
return getAge(date, new GregorianCalendar(tz));
IntegergetAge(Date dateNaissance)
Retourne l'age en utilisant la date de naissance.
Integer ageToReturn = null;
if (dateNaissance != null) {
    Calendar dateOfBirth = Calendar.getInstance();
    dateOfBirth.setTime(dateNaissance);
    Calendar today = Calendar.getInstance();
    int age = today.get(Calendar.YEAR) - dateOfBirth.get(Calendar.YEAR);
    dateOfBirth.add(Calendar.YEAR, age);
    if (today.before(dateOfBirth)) {
...
intgetAge(Date time, Date birth)
get Age
if (time == null) {
    throw new NullPointerException("time is null");
if (birth == null) {
    throw new NullPointerException("birth is null");
Calendar c1 = Calendar.getInstance();
c1.setTimeInMillis(time.getTime());
...
intgetAge(final Date birthDay, final Date currDate)
Returns the age in years according to the date of birth passed and the date passed as current.
final Calendar endDate = Calendar.getInstance();
final Calendar startDate = Calendar.getInstance();
startDate.setTime(birthDay);
endDate.setTime(currDate);
int years = endDate.get(Calendar.YEAR) - startDate.get(Calendar.YEAR);
startDate.set(Calendar.YEAR, endDate.get(Calendar.YEAR));
if (startDate.after(endDate)) {
    years--;
...
IntegergetAge(String year)
get Age
Calendar c = Calendar.getInstance();
if (year == null) {
    return 20;
year = year.substring(0, 4);
Integer age = c.get(Calendar.YEAR) - Integer.parseInt(year);
return age;
StringgetAge1(Date birthDay)
get Age
if (null == birthDay)
    return "-";
Calendar cal = Calendar.getInstance();
if (cal.before(birthDay)) {
    throw new IllegalArgumentException("The birthDay is before Now.It's unbelievable!");
int yearNow = cal.get(Calendar.YEAR);
int monthNow = cal.get(Calendar.MONTH);
...
intgetAgeAt(final Date birthday, final Date date)
get Age At
if (birthday == null || date == null || date.compareTo(birthday) < 0) {
    return 0;
final Calendar cal = Calendar.getInstance();
cal.setTime(birthday);
final int birthYear = cal.get(Calendar.YEAR);
final int birthMonth = cal.get(Calendar.MONTH);
final int birthDay = cal.get(Calendar.DAY_OF_MONTH);
...
StringgetAgeFromBirthDate(Date birth, boolean estimate)
get Age From Birth Date
String result = "";
Calendar now = Calendar.getInstance();
Calendar bd = Calendar.getInstance();
bd.setTime(birth);
long ONE_DAY = 1000 * 60 * 60 * 24;
long date1_ms = now.getTimeInMillis();
long date2_ms = bd.getTimeInMillis();
long difference_ms = Math.abs(date1_ms - date2_ms);
...
IntegergetAgeFromBirthday(Date birthday)
get Age From Birthday
if (birthday == null) {
    return null;
Calendar dateOfBirth = Calendar.getInstance();
dateOfBirth.setTime(birthday);
Calendar today = Calendar.getInstance();
int age = today.get(Calendar.YEAR) - dateOfBirth.get(Calendar.YEAR);
dateOfBirth.add(Calendar.YEAR, age);
...
IntegergetAgeFromBirthday(Date date)
get Age From Birthday
return new Date().getYear() - date.getYear();