Here you can find the source of ageInYears(java.util.Date dateUtil)
public static int ageInYears(java.util.Date dateUtil)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; import java.util.GregorianCalendar; public class Main { public static int ageInYears(java.util.Date dateUtil) { Calendar calend = new GregorianCalendar(); java.util.Date now = new java.util.Date(); calend.set(Calendar.HOUR_OF_DAY, 0); calend.set(Calendar.MINUTE, 0); calend.set(Calendar.SECOND, 0); calend.set(Calendar.MILLISECOND, 0); calend.setTimeInMillis(now.getTime() - dateUtil.getTime()); float result = 0; result = calend.get(Calendar.YEAR) - 1970; result += (float) calend.get(Calendar.MONTH) / (float) 12; return (int) result; }/* w w w. ja va 2 s .c o m*/ }