Java Date Compare by Day isSameDay(Date d1, Date d2)

Here you can find the source of isSameDay(Date d1, Date d2)

Description

Compares two dates.

License

Open Source License

Parameter

Parameter Description
d1 first date
d2 second date

Return

true if both dates are the same day

Declaration

public static synchronized boolean isSameDay(Date d1, Date d2) 

Method Source Code

//package com.java2s;
/*//from w  w w .j  av  a  2 s . co m
 *  NachoCalendar
 *
 * Project Info:  http://nachocalendar.sf.net
 *
 * 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.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 *
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
 * in the United States and other countries.]
 *
 * Changes
 * -------
 * 
 * 2005-01-09   Cleanups
 * 2004-12-28   convertToDate: Added null support.
 * 2004-12-21   Added isToday() funcion
 * 
 * -------
 *
 * CalendarUtils.java
 *
 * Created on October 22, 2004, 10:01 PM
 */

import java.util.Calendar;
import java.util.Date;

public class Main {
    private static Calendar calendar1, calendar2;

    private static synchronized boolean isSameDay() {
        if (calendar1.get(Calendar.DAY_OF_YEAR) != calendar2.get(Calendar.DAY_OF_YEAR))
            return false;
        if (calendar1.get(Calendar.YEAR) != calendar2.get(Calendar.YEAR))
            return false;
        return true;
    }

    /**
     * Compares two dates.
     * @param d1 first date
     * @param d2 second date
     * @return true if both dates are the same day
     */
    public static synchronized boolean isSameDay(Date d1, Date d2) {
        calendar1.setTime(d1);
        calendar2.setTime(d2);
        return isSameDay();
    }
}

Related

  1. isSameDay(Date a, Date b)
  2. isSameDay(Date a, Date b)
  3. isSameDay(Date d1, Date d2)
  4. isSameDay(Date d1, Date d2)
  5. isSameDay(Date date)
  6. isSameDay(Date date1, Date date2)
  7. isSameDay(Date date1, Date date2)