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;

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

public class Main {

    public static int compareDate(Date date1, Date date2) {
        Calendar calendar1 = Calendar.getInstance();
        Calendar calendar2 = Calendar.getInstance();
        calendar1.setTime(date1);/*from   ww  w.  java  2  s  . co m*/
        calendar2.setTime(date2);
        calendar1.set(Calendar.SECOND, 0);
        calendar2.set(Calendar.SECOND, 0);
        calendar1.set(Calendar.MILLISECOND, 0);
        calendar2.set(Calendar.MILLISECOND, 0);
        long diff = calendar1.getTimeInMillis() - calendar2.getTimeInMillis();
        int minute = (int) (diff / (1000 * 60));
        if (minute > 0) {
            return 1;
        } else if (minute == 0) {
            return 0;
        }
        return -1;
    }
}

Related

  1. compareDate(Date d1, Date d2)
  2. compareDate(Date d1, Date d2)
  3. compareDate(Date d1, Date d2)
  4. CompareDate(Date date, Date otherdate)
  5. compareDate(Date date1)
  6. compareDate(Date DATE1, Date DATE2)
  7. compareDate(Date date1, Date date2)
  8. compareDate(Date date1, Date date2)
  9. compareDate(Date date1, Date date2)