Here you can find the source of getYearDiff(Date date1, Date date2)
public static int getYearDiff(Date date1, Date date2)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; public class Main { public static int getYearDiff(Date date1, Date date2) { if (date1 == null || date2 == null) { return 0; }//from w w w . ja v a 2 s . c o m Calendar calendar1 = Calendar.getInstance(); calendar1.setTime(date1); int year1 = calendar1.get(Calendar.YEAR); Calendar calendar2 = Calendar.getInstance(); calendar2.setTime(date2); int year2 = calendar2.get(Calendar.YEAR); return Math.abs(year1 - year2); } }