Java Calendar Compare compareDates(final Calendar firstCal, final Calendar secondCal)

Here you can find the source of compareDates(final Calendar firstCal, final Calendar secondCal)

Description

compare Dates

License

Open Source License

Declaration

public static int compareDates(final Calendar firstCal, final Calendar secondCal) 

Method Source Code

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

import java.util.Calendar;

public class Main {
    public static int compareDates(final Calendar firstCal, final Calendar secondCal) {
        int result = 0;
        if (firstCal.get(Calendar.YEAR) > secondCal.get(Calendar.YEAR))
            result = 1;//w  ww  .ja va2  s .c  o m
        else if (firstCal.get(Calendar.YEAR) < secondCal.get(Calendar.YEAR))
            result = -1;
        else {
            if (firstCal.get(Calendar.MONTH) > secondCal.get(Calendar.MONTH))
                result = 1;
            else if (firstCal.get(Calendar.MONTH) < secondCal.get(Calendar.MONTH))
                result = -1;
            else {
                if (firstCal.get(Calendar.DATE) > secondCal.get(Calendar.DATE))
                    result = 1;
                else if (firstCal.get(Calendar.DATE) < secondCal.get(Calendar.DATE))
                    result = -1;
            }
        }
        return result;
    }
}

Related

  1. compare(Calendar c1, Calendar c2)
  2. compare(Calendar c1, Calendar c2)
  3. compare(Calendar c1, Calendar c2, int what)
  4. compareCalendar(Calendar cal1, Calendar cal2)
  5. compareDates(Calendar date1, Calendar date2)
  6. compareDateTime(final Calendar firstCal, final Calendar secondCal)
  7. compareDay(Calendar calendar, Calendar calendar1)
  8. compareSameDay(Calendar first, Calendar second)
  9. compareTime(final Calendar firstCal, final Calendar secondCal)