before(Object): This method is available in java.util.GregorianCalendar class of Java.
Syntax:
boolean java.util.Calendar.before(Object when)
This method takes one argument of type Object as its parameter. This method returns whether this Calendar represents a time before the time represented by the specified Object.
Parameters: One parameter is required for this method.
when: the Object to be compared.
Returns: true if the time of this Calendar is before the time represented by when; false otherwise.
Exceptions: NA
Approach
Java
import java.util.GregorianCalendar;public class GregorianCalendarbefore {public static void main(String[] args) {GregorianCalendar cal = (GregorianCalendar)GregorianCalendar.getInstance();GregorianCalendar when = (GregorianCalendar)GregorianCalendar.getInstance();when.add(GregorianCalendar.MONTH, 1);System.out.println(cal.before(when));}}
Output:
true
No comments:
Post a Comment