Java Date Compare compareDate(Date date1, Date date2)

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

Description

compare Date

License

Open Source License

Declaration

public static int compareDate(Date date1, Date date2) 

Method Source Code

//package com.java2s;
/**/* w  w  w . j  av a2s  .com*/
*    Copyright (C) 2012 Cardinal Info.Tech.Co.,Ltd.
*
*    This program is free software: you can redistribute it and/or modify
*    it under the terms of the GNU Affero General Public License, version 3,
*    as published by the Free Software Foundation.
*
*    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 int compareDate(Date date1, Date date2) {
        Calendar c1 = Calendar.getInstance();
        c1.setTime(date1);
        Calendar c2 = Calendar.getInstance();
        c2.setTime(date2);

        return compareDate(c1, c2);
    }

    public static int compareDate(Calendar cal1, Calendar cal2) {
        int value = 9;

        if (cal1.before(cal2)) {
            value = -1;
        }
        if (cal1.after(cal2)) {
            value = 1;
        }
        if (cal1.equals(cal2)) {
            value = 0;
        }
        return value;
    }
}

Related

  1. compareDate(Date DATE1, Date DATE2)
  2. compareDate(Date date1, Date date2)
  3. compareDate(Date date1, Date date2)
  4. compareDate(Date date1, Date date2)
  5. compareDate(Date date1, Date date2)
  6. compareDate(Date date1, Date date2, String pattern)
  7. compareDate(Date first, Date second)
  8. compareDate(Date sourceDate, Date targetDate)
  9. compareDate(Date start, Date end)