Java examples for java.util:Date Compare
Checks the given dates for being equal.
/*// ww w .jav a 2 s. c o m * $Id: CalendarUtils.java 3916 2011-01-12 10:21:58Z kleopatra $ * * Copyright 2007 Sun Microsystems, Inc., 4150 Network Circle, * Santa Clara, California 95054, U.S.A. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ //package com.java2s; import java.util.Date; public class Main { public static void main(String[] argv) throws Exception { Date current = new Date(); Date date = new Date(); System.out.println(areEqual(current, date)); } /** * Checks the given dates for being equal. * * @param current one of the dates to compare * @param date the otherr of the dates to compare * @return true if the two given dates both are null or both are not null and equal, * false otherwise. */ public static boolean areEqual(Date current, Date date) { if ((date == null) && (current == null)) { return true; } if (date != null) { return date.equals(current); } return false; } }