The clear(int cal_field) method in Calendar class is used to set a given calendar field value and the time value of this Calendar undefined.
Note: Implementation of calendar class may use default field values for date and time calculations.
public final void clear(int cal_field)
Parameters: The method takes one parameter cal_field of Integer type and refers to the field value that is to be made undefined.
Return Value: The method does not return any value.
Below programs illustrate the working of clear() Method of Calendar class:
Current Date&Time: Wed Mar 27 09:03:26 UTC 2019 After clear method: Sun Jan 27 09:03:26 UTC 2019
Current Date&Time: Wed Mar 27 09:03:32 UTC 2019 After clear method: Fri Mar 27 09:03:32 UTC 1970
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.