Here you can find the source of getYears(java.util.Date date0, java.util.Date date1)
public static int getYears(java.util.Date date0, java.util.Date date1)
//package com.java2s; import java.util.Calendar; public class Main { public static int getYears(java.util.Date date0, java.util.Date date1) { Calendar calendar0 = Calendar.getInstance(); calendar0.setTime(date0);/* www . j av a 2 s . c om*/ Calendar calendar1 = Calendar.getInstance(); calendar1.setTime(date1); int year0 = calendar0.get(Calendar.YEAR); int year1 = calendar1.get(Calendar.YEAR); int years = year1 - year0; return years; } }