Here you can find the source of compareIgnoreSecond(Date date, Date anotherDate)
public static int compareIgnoreSecond(Date date, Date anotherDate)
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static int compareIgnoreSecond(Date date, Date anotherDate) { if (date == null) { date = new Date(); }//from www .j ava2 s . c o m if (anotherDate == null) { anotherDate = new Date(); } Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); date = cal.getTime(); cal.setTime(anotherDate); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); anotherDate = cal.getTime(); return date.compareTo(anotherDate); } public static String getTime(Date date) { if (date == null) { return null; } SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss"); return format.format(date); } }