java.util.Calendar.after() is a method in Calendar class of java.util package. The method returns true if the time represented by this Calendar is after the time represented by when Object. If it is not the case, false is returned.
Syntax :
public boolean after(Object when)
Where, when is the Object
that is to be compared.
Below are some examples to understand the implementation of the Calendar.after() function in a better way :
Example 1 :
import java.util.*;
class GFG {
public static void main(String[] args)
throws InterruptedException {
Calendar cal_obj1 = Calendar.getInstance();
System.out.println( "Time 1 : " + cal_obj1.getTime());
Calendar cal_obj2 = Calendar.getInstance();
System.out.println( "Time 2 : " + cal_obj2.getTime());
System.out.println(cal_obj1.after(cal_obj2));
}
}
|
Output :
Time 1 : Thu Mar 01 09:26:04 UTC 2018
Time 2 : Thu Mar 01 09:26:04 UTC 2018
false
Example 2 :
import java.util.*;
class GFG {
public static void main(String[] args)
{
Calendar cal_obj1 = Calendar.getInstance();
Calendar cal_obj2 = Calendar.getInstance();
System.out.println( "Current date is : " + cal_obj1.getTime());
cal_obj2.set(Calendar.YEAR, 2010 );
System.out.println( "Result : " + cal_obj1.after(cal_obj2));
}
}
|
Output :
Current date is : Thu Mar 01 09:27:19 UTC 2018
Result : true