Here you can find the source of sameYear(Date date1, Date date2)
public static boolean sameYear(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 boolean sameYear(Date date1, Date date2) { if (date1 == null || date2 == null) { return false; }/*from w w w . ja v a2 s. co m*/ Calendar calendar = Calendar.getInstance(); calendar.setTime(date1); Calendar calendar2 = Calendar.getInstance(); calendar.setTime(date2); return calendar.get(Calendar.YEAR) - calendar.get(Calendar.YEAR) == 0; } }