Here you can find the source of getAge(Date birthday)
public static int getAge(Date birthday)
//package com.java2s; //License from project: Open Source License import java.util.Date; import java.util.Calendar; public class Main { public static int getAge(Date birthday) { Calendar birthCal = Calendar.getInstance(); birthCal.setTime(birthday);/*from w w w. j a v a2 s. c o m*/ Calendar today = Calendar.getInstance(); int age = today.get(Calendar.YEAR) - birthCal.get(Calendar.YEAR); if (today.get(Calendar.DAY_OF_YEAR) < birthCal .get(Calendar.DAY_OF_YEAR)) { age--; } return age; } }