Here you can find the source of compareYear(java.util.Date date1, java.util.Date date2)
public static int compareYear(java.util.Date date1, java.util.Date date2)
//package com.java2s; import java.util.Calendar; public class Main { public static int compareYear(java.util.Date date1, java.util.Date date2) { if (date1 == null || date2 == null) return 0; Calendar calendar = Calendar.getInstance(); calendar.setTime(date1);/*w w w.j a va 2 s. c om*/ int year1 = calendar.get(Calendar.YEAR); calendar.setTime(date2); int year2 = calendar.get(Calendar.YEAR); return year1 - year2; } }