Here you can find the source of compare(final Date one, final Date another)
protected static Integer compare(final Date one, final Date another)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; import java.util.Date; public class Main { protected static Integer compare(final Date one, final Date another) { if (one == null || another == null) { return null; }// w ww .j a v a2 s. c o m final Calendar cal1 = Calendar.getInstance(); final Calendar cal2 = Calendar.getInstance(); cal1.setTime(one); cal2.setTime(another); int age = Math.abs(cal1.get(Calendar.YEAR) - cal2.get(Calendar.YEAR)); return cal1.getTime().before(cal2.getTime()) ? age-- : age; } }