Here you can find the source of calculateAge(Date dob)
public static Integer calculateAge(Date dob)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Main { public static Integer calculateAge(Date dob) { Calendar cal = new GregorianCalendar(); cal.setTime(dob);//from w ww. j a va 2s.co m Calendar now = new GregorianCalendar(); int res = now.get(Calendar.YEAR) - cal.get(Calendar.YEAR); if ((cal.get(Calendar.MONTH) > now.get(Calendar.MONTH)) || (cal.get(Calendar.MONTH) == now.get(Calendar.MONTH) && cal.get(Calendar.DAY_OF_MONTH) > now.get(Calendar.DAY_OF_MONTH))) { res--; } return res; } }