The Java.util.Calendar.compareTo () method compares the time value (the millisecond offset) between the Calendar object and the Anothercalendar object.
Statement
The following is a declaration of the Java.util.Calendar.compareTo () method
Public int compareTo (Calendar Anothercalendar)
Parameters
return value
If the time represented by the parameter is equal to the time method represented by this calendar object, it returns 0, or if the time of this calendar is a value that is less than 0 before the time represented by the parameter, or if the time represented by the calendar returns a value greater than 0.
Abnormal
Example
The following example shows the use of the Java.util.calendar.compareTo () method.
PackageCom.yiibai;ImportJava.util.*; Public classCalendardemo { Public Static voidMain (string[] args) {//create the calendar at the different datesCalendar Cal1 =NewGregorianCalendar (2015, 8, 15); Calendar Cal2=NewGregorianCalendar (2008, 1, 02); //Compare the time values represented by the calendar objects. inti =Cal1.compareto (CAL2); //return positive value if equals else return negative valueSYSTEM.OUT.PRINTLN ("The result is:" +i); //Compare again but with the calendars swapped intj =Cal2.compareto (CAL); //return positive value if equals else return negative valueSYSTEM.OUT.PRINTLN ("The result is:" +j); }}
Let's compile and run the above program, which will produce the following results:
The result is:1 Theresult is:-1
Android Development Note "Java.util.Calendar.compareTo ()"