Here you can find the source of yearTimeDiff(Date d1, Date d2)
public static int yearTimeDiff(Date d1, Date d2)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; public class Main { public static int yearTimeDiff(Date d1, Date d2) { assertDateParamsRequired(d1, d2); Calendar c1 = Calendar.getInstance(); c1.setTime(d1);// w ww . j av a 2 s . c o m Calendar c2 = Calendar.getInstance(); c2.setTime(d2); return c1.get(Calendar.YEAR) - c2.get(Calendar.YEAR); } private static void assertDateParamsRequired(Date... dates) { for (Date date : dates) { if (date == null) { throw new IllegalArgumentException("The Date type parameters are required."); } } } }