Java Calendar Compare compare(Calendar c1, Calendar c2)

Here you can find the source of compare(Calendar c1, Calendar c2)

Description

compare

License

Apache License

Declaration

public static int compare(Calendar c1, Calendar c2) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public static int compare(Calendar c1, Calendar c2) {
        if (c1 == null || c2 == null)
            return -1;
        long r = c1.getTimeInMillis() - c2.getTimeInMillis();
        if (r > 0)
            return 1;
        else if (r == 0)
            return 0;
        else//from   ww w  . j  a v  a2 s.  c  o m
            return 2;
    }

    public static int compare(Date c1, Date c2) {
        if (c1 == null || c2 == null)
            return -1;
        long r = c1.getTime() - c2.getTime();

        if (r > 0)
            return 1;
        else if (r == 0)
            return 0;
        else
            return 2;
    }
}

Related

  1. compare(Calendar c1, Calendar c2)
  2. compare(Calendar c1, Calendar c2, int what)
  3. compareCalendar(Calendar cal1, Calendar cal2)
  4. compareDates(Calendar date1, Calendar date2)
  5. compareDates(final Calendar firstCal, final Calendar secondCal)