Here you can find the source of getAge(Date time, Date birth)
Parameter | Description |
---|---|
time | a parameter |
birth | a parameter |
public static int getAge(Date time, Date birth)
//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); } }