Here you can find the source of getAge(Date birthday)
public static Integer getAge(Date birthday)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; public class Main { public static Integer getAge(Date birthday) { if (birthday == null) { return null; }// ww w . ja v a 2 s . co m Calendar calendar = Calendar.getInstance(); calendar.setTime(birthday); int startY = calendar.get(Calendar.YEAR); calendar.setTime(new Date()); int endY = calendar.get(Calendar.YEAR); int age = endY - startY; return age >= 0 ? age : 0; } }