Java Calendar Compare compare(Calendar c1, Calendar c2)

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

Description

Compare to calendars.

License

Open Source License

Parameter

Parameter Description
c1 First calendar.
c2 Second calendar

Return

1 if c1 > c2, 0 if c1 = c2, -1 if c1 < c2.

Declaration

public static int compare(Calendar c1, Calendar c2) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.Calendar;

public class Main {
    /**/*from   ww w. j  ava 2s  .  c om*/
     * Compare to calendars.
     * 
     * @param c1 First calendar.
     * @param c2 Second calendar
     * @return 1 if c1 > c2, 0 if c1 = c2, -1 if c1 < c2.
     */
    public static int compare(Calendar c1, Calendar c2) {
        long m1 = c1.getTime().getTime();
        long m2 = c2.getTime().getTime();

        if (m1 < m2) {
            return -1;
        }
        if (m1 > m2) {
            return 1;
        }
        return 0;
    }
}

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)