Java Calendar - clear() Method
The java.util.Calendar.clear() method is used to set all the calendar field values and the time value (millisecond offset from the Epoch) of this Calendar undefined. A Calendar implementation class may use its specific default field values for date/time calculations.
Syntax
public final void clear()
Parameters
No parameter is required.
Return Value
void type.
Exception
NA
Example:
In the example below, the java.util.Calendar.clear() method is used to set all the calendar field values and the time value of the given Calendar undefined.
import java.util.*; public class MyClass { public static void main(String[] args) { //creating a Calendar with specified date Calendar Cal = new GregorianCalendar(2018, 10, 25); //printing the calendar System.out.println("The Calendar is: " + Cal.getTime()); //using the clear() method to set all calendar //field values to undefined Cal.clear(); //printing the calendar System.out.println("New Calendar is: " + Cal.getTime()); } }
The output of the above code will be:
The Calendar is: Sun Nov 25 00:00:00 UTC 2018 New Calendar is: Thu Jan 01 00:00:00 UTC 1970
❮ Java.util - Calendar