Here you can find the source of calculateAge(Date dateOfBirth)
private static int calculateAge(Date dateOfBirth)
//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; } }