Here you can find the source of differenceOnYear(Date date1, Date date2)
public static int differenceOnYear(Date date1, Date date2)
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { public static int differenceOnYear(Date date1, Date date2) { if (date1 == null || date2 == null) { return 0; }/*from w w w. j a v a 2 s. co m*/ int year1 = getDateYear(date1); int year2 = getDateYear(date2); return Math.abs(year1 - year2); } public static int getDateYear(Date date) { if (date == null) return 0; Calendar cal = Calendar.getInstance(); cal.setTime(date); return cal.get(Calendar.YEAR); } }