Java Date Compare by Day sameDay(Date date1, Date date2)

Here you can find the source of sameDay(Date date1, Date date2)

Description

same Day

License

Open Source License

Declaration

public static boolean sameDay(Date date1, Date date2) 

Method Source Code


//package com.java2s;
/*//from  w  w w  .ja  v a 2  s.  com
 * 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 sameDay(Date date1, Date date2) {
        Calendar cal1 = Calendar.getInstance();
        Calendar cal2 = Calendar.getInstance();
        cal1.setTime(date1);
        cal2.setTime(date2);

        int date1Year = cal1.get(Calendar.YEAR);
        int date1Month = cal1.get(Calendar.MONTH) + 1;
        int date1Day = cal1.get(Calendar.DATE);
        int date2Year = cal2.get(Calendar.YEAR);
        int date2Month = cal2.get(Calendar.MONTH) + 1;
        int date2Day = cal2.get(Calendar.DATE);

        if (date1Year == date2Year && date1Month == date2Month && date1Day == date2Day) {
            return true;
        }
        return false;
    }
}

Related

  1. isSameDay(Date date1, Date date2)
  2. isSameDay(Date day1, Date day2)
  3. isSameDay(Date lastUpgradeTime)
  4. isSameDay(final Date date1, final Date date2)
  5. isSameDayWithToday(Date date)
  6. sameDay(Date date1, Date date2)
  7. sameDay(Date date1, Date date2)
  8. sameDay(Date date1, Date date2)
  9. sameDay(Date dateOne, Date dateTwo)