Java Age Calculate calculateAge(Date dateOfBirth)

Here you can find the source of calculateAge(Date dateOfBirth)

Description

calculate Age

License

Open Source License

Declaration

private static int calculateAge(Date dateOfBirth) 

Method Source Code

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

import java.util.Calendar;

import java.util.Date;

public class Main {
    private static int calculateAge(Date dateOfBirth) {
        Calendar dob = Calendar.getInstance();
        dob.setTime(dateOfBirth);//  w w  w . j a  v  a  2  s  .  co  m
        Calendar today = Calendar.getInstance();

        int age = today.get(Calendar.YEAR) - dob.get(Calendar.YEAR);

        if (today.get(Calendar.DAY_OF_YEAR) < dob.get(Calendar.DAY_OF_YEAR)) {
            age--;
        }

        return age;
    }
}

Related

  1. ageInYears(java.util.Date dateUtil)
  2. calculateAge(Date aBirthdate)
  3. calculateAge(Date aDateFrom, Date aDateTo)
  4. calculateAge(Date birthDate)
  5. calculateAge(Date birthday)
  6. calculateAge(Date dob)
  7. calculateAge(Date DOB)
  8. calculateAgeInMonth(final Date birthDate, final Date asOfDate)
  9. calculateAgeInWeek(final Date birthDate, final Date asOfDate)