Java Date Equal equalsToDate(Date date1, Date date2, boolean checkTime)

Here you can find the source of equalsToDate(Date date1, Date date2, boolean checkTime)

Description

equals To Date

License

Open Source License

Declaration

public static boolean equalsToDate(Date date1, Date date2, boolean checkTime) 

Method Source Code

//package com.java2s;
/*//from   ww w  .  j av a 2s. c  o  m
 * Aipo is a groupware program developed by Aimluck,Inc.
 * Copyright (C) 2004-2011 Aimluck,Inc.
 * http://www.aipo.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.Calendar;

import java.util.Date;

public class Main {

    public static boolean equalsToDate(Date date1, Date date2, boolean checkTime) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date1);
        int date1Year = cal.get(Calendar.YEAR);
        int date1Month = cal.get(Calendar.MONTH) + 1;
        int date1Day = cal.get(Calendar.DATE);
        int date1Hour = cal.get(Calendar.HOUR);
        int date1Minute = cal.get(Calendar.MINUTE);
        cal.setTime(date2);
        int date2Year = cal.get(Calendar.YEAR);
        int date2Month = cal.get(Calendar.MONTH) + 1;
        int date2Day = cal.get(Calendar.DATE);
        int date2Hour = cal.get(Calendar.HOUR);
        int date2Minute = cal.get(Calendar.MINUTE);
        if (checkTime) {
            if (date1Year == date2Year && date1Month == date2Month && date1Day == date2Day && date1Hour == date2Hour
                    && date1Minute == date2Minute) {
                return true;
            }
        } else {
            if (date1Year == date2Year && date1Month == date2Month && date1Day == date2Day) {
                return true;
            }
        }
        return false;
    }
}

Related

  1. datesEqualToSecond(Date date1, Date date2)
  2. equal(Date date, Date other)
  3. equalDateByDay(Date date1, Date date2)
  4. equalDates(Date first, Date second)
  5. equalsIgnoreTime(final Date d1, final Date d2)
  6. equalsWoTime(final Date date1, final Date date2)
  7. firstLessOrEqualSecond(Date firstDate, Date secondDate)
  8. hourEqual(Date date1, Date date2)
  9. isEqual(Date date1, Date date2)