Java tutorial
import static java.lang.System.out; import static java.util.Calendar.HOUR_OF_DAY; import static java.util.Calendar.MILLISECOND; import static java.util.Calendar.MINUTE; import static java.util.Calendar.SECOND; import java.util.Calendar; import java.util.Date; public class Main { public static void main(String[] args) throws InterruptedException { Date date = new Date(); Thread.sleep(1); Date other = new Date(); out.printf("equals? = %s, hashCode? = %s %n", (date.equals(other)), (date.hashCode() == other.hashCode())); Date todayeOne = trim(date); Date todayTwo = trim(other); out.printf("equals? = %s, hashCode? = %s %n", (todayeOne.equals(todayTwo)), (todayeOne.hashCode() == todayTwo.hashCode())); } public static Date trim(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.set(HOUR_OF_DAY, 0); cal.set(MINUTE, 0); cal.set(SECOND, 0); cal.set(MILLISECOND, 0); return cal.getTime(); } }