Java Age Calculate getAge(Date time, Date birth)

Here you can find the source of getAge(Date time, Date birth)

Description

get Age

License

Open Source License

Parameter

Parameter Description
time a parameter
birth a parameter

Declaration

public static int getAge(Date time, Date birth) 

Method Source Code

//package com.java2s;

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

public class Main {
    /**/*  ww  w.j a v a  2s. c  o m*/
     * 
     * @param time
     * @param birth
     * @return
     */
    public static int getAge(Date time, Date birth) {
        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());
        Calendar c2 = Calendar.getInstance();
        c2.setTimeInMillis(birth.getTime());
        return c1.get(Calendar.YEAR) - c2.get(Calendar.YEAR);
    }
}

Related

  1. getAge(Date birthday)
  2. getAge(Date birthday)
  3. getAge(Date date)
  4. getAge(Date date, TimeZone tz)
  5. getAge(Date dateNaissance)
  6. getAge(final Date birthDay, final Date currDate)
  7. getAge(String year)
  8. getAge1(Date birthDay)
  9. getAgeAt(final Date birthday, final Date date)