Here you can find the source of getYearsBetweenDate(Date begin, Date end)
public static int getYearsBetweenDate(Date begin, Date end)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; public class Main { public static int getYearsBetweenDate(Date begin, Date end) { int bYear = getDateField(begin, Calendar.YEAR); int eYear = getDateField(end, Calendar.YEAR); return eYear - bYear; }//from w w w . j av a 2 s. c o m private static int getDateField(Date date, int field) { Calendar c = getCalendar(); c.setTime(date); return c.get(field); } private static Calendar getCalendar() { return Calendar.getInstance(); } public static int get(int field, Date date) { Calendar c = Calendar.getInstance(); c.setTime(date); return c.get(field); } }