Here you can find the source of isSameDate(Date date1, Date date2)
Parameter | Description |
---|---|
date1 | a parameter |
date2 | a parameter |
public static boolean isSameDate(Date date1, Date date2)
//package com.java2s; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Main { /**// ww w . ja v a2 s. c o m * Returns true if the 2 dates are the same, regardless of the time * * @param date1 * @param date2 * @return */ public static boolean isSameDate(Date date1, Date date2) { if (date1 == null || date2 == null) { return false; } Calendar c1 = (GregorianCalendar) Calendar.getInstance(); c1.setTime(date1); c1.set(Calendar.HOUR_OF_DAY, 0); c1.set(Calendar.MINUTE, 0); c1.set(Calendar.SECOND, 0); c1.set(Calendar.MILLISECOND, 0); Calendar c2 = (GregorianCalendar) Calendar.getInstance(); c2.setTime(date2); c2.set(Calendar.HOUR_OF_DAY, 0); c2.set(Calendar.MINUTE, 0); c2.set(Calendar.SECOND, 0); c2.set(Calendar.MILLISECOND, 0); return c1.equals(c2); } }