java.util.Calendar after(Object when)
Description :
This java tutorial shows how to use the after(Object when) method of Calendar class of java.util package. This method returns whether this Calendar represents a time after the time represented by the specified Object.
Method Syntax :
public boolean after(Object when)
Parameter Input :
DataType | Parameter | Description |
---|---|---|
Object | when | the Object to be compared |
Method Returns :
This method returns true if the time of this Calendar is after the time represented by when; false otherwise.
Compatibility Version :
Requires Java 1.1 and up
Exception :
N/A
Java Code Example :
This java example source code demonstrates the use of after(Object when) method of Calendar class.
package com.javatutorialhq.java.examples;import java.util.Calendar;
/* * This example source code demonstrates the use of * after(Object when) method of Calendar class */
public class CalendarAfterExample {
public static void main(String
[] args) throws InterruptedException {
Calendar cal1 = Calendar.getInstance(); System.out.println("Time 1:" + cal1.getTime()); // sleep for 5 seconds Thread.sleep(5000); Calendar cal2 = Calendar.getInstance(); System.out.println("Time 2:" + cal2.getTime()); System.out.println(cal2.after(cal1)); // creating an object which is not a calendar Object c = new String(""); // this will always return false System.out.println(cal1.before(c)); } }
Sample Output :
Running the after(Object when) method example source code of Calendar class will give you the following output:
Time 1:Sun Feb 08 00:08:31 CST 2015 Time 2:Sun Feb 08 00:08:36 CST 2015 true false
Exception Scenario :
N/A
Similar Method :
- N/A
Suggested Reading List :
References :