Java tutorial
import java.util.Calendar; import java.util.Date; /* * The contents of this file are subject to the terms of the Common Development * and Distribution License (the License). You may not use this file except in * compliance with the License. * * You can get a copy of the License at http://www.thinkingrock.com.au/cddl.html * or http://www.thinkingrock.com.au/cddl.txt. * * When distributing Covered Code, include this CDDL Header Notice in each file * and include the License file at http://www.thinkingrock.com.au/cddl.txt. * If applicable, add the following below the CDDL Header, with the fields * enclosed by brackets [] replaced by your own identifying information: * "Portions Copyright [year] [name of copyright owner]" * * The Original Software is ThinkingRock. The Initial Developer of the Original * Software is Avente Pty Ltd, Australia. * * Portions Copyright 2006-2007 Avente Pty Ltd. All Rights Reserved. */ public class Util { /** * <p>Checks if two dates are on the same day ignoring time.</p> * @param date1 the first date, not altered, not null * @param date2 the second date, not altered, not null * @return true if they represent the same day * @throws IllegalArgumentException if either date is <code>null</code> */ public static boolean isSameDay(Date date1, Date date2) { if (date1 == null || date2 == null) { throw new IllegalArgumentException("The dates must not be null"); } Calendar cal1 = Calendar.getInstance(); cal1.setTime(date1); Calendar cal2 = Calendar.getInstance(); cal2.setTime(date2); return isSameDay(cal1, cal2); } }