Java Age Calculate ageInYears(java.util.Date dateUtil)

Here you can find the source of ageInYears(java.util.Date dateUtil)

Description

age In Years

License

Open Source License

Declaration

public static int ageInYears(java.util.Date dateUtil) 

Method Source Code


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

import java.util.Calendar;
import java.util.GregorianCalendar;

public class Main {
    public static int ageInYears(java.util.Date dateUtil) {
        Calendar calend = new GregorianCalendar();
        java.util.Date now = new java.util.Date();
        calend.set(Calendar.HOUR_OF_DAY, 0);
        calend.set(Calendar.MINUTE, 0);
        calend.set(Calendar.SECOND, 0);
        calend.set(Calendar.MILLISECOND, 0);

        calend.setTimeInMillis(now.getTime() - dateUtil.getTime());

        float result = 0;
        result = calend.get(Calendar.YEAR) - 1970;
        result += (float) calend.get(Calendar.MONTH) / (float) 12;
        return (int) result;
    }/* w  w w.  ja va  2 s  .c  o  m*/
}

Related

  1. age(Date birthdate, Date asOf)
  2. age(Date dob)
  3. age(int year, int month, int date)
  4. ageAcceptable(final Date doB, final Date now, final int acceptedAge)
  5. calculateAge(Date aBirthdate)
  6. calculateAge(Date aDateFrom, Date aDateTo)
  7. calculateAge(Date birthDate)
  8. calculateAge(Date birthday)