Here you can find the source of getYearsBetween(Date startDate, Date endDate)
public static long getYearsBetween(Date startDate, Date endDate)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; import java.util.Date; import java.util.TimeZone; public class Main { public static final long MILIS_PER_YEAR = 31540000000L; public static long getYearsBetween(Date startDate, Date endDate) { long msBetween = getMsBetween(startDate, endDate); return miliSecondsToYears(msBetween); }/* w w w . j a va2 s . c o m*/ public static long getMsBetween(Date startDate, Date endDate) { Calendar cal = getCalendar(); cal.setTime(startDate); long startMs = cal.getTimeInMillis(); cal.setTime(endDate); long endMs = cal.getTimeInMillis(); return endMs - startMs; } public static long miliSecondsToYears(long ms) { return ms / MILIS_PER_YEAR; } public static Calendar getCalendar() { return getCalendar("GMT"); } public static Calendar getCalendar(String timezone) { Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone(timezone)); return cal; } }