Java.util.Calendar.clear() Method


Description

The java.util.Calendar.clear() method sets all the calendar field values and the time value of this Calendar undefined.A Calendar implementation class may use default field values for date and time calculations.

Declaration

Following is the declaration for java.util.Calendar.clear() method

public final void clear()

Parameters

NA

Return Value

This method does not return any value.

Exception

NA

Example

The following example shows the usage of java.util.Calendar.clear() method.

package com.tutorialspoint;

import java.util.*;

public class CalendarDemo {
   public static void main(String[] args) {
   
      // create calendar object
      Calendar cal = Calendar.getInstance();

      // displays the current date and time
      System.out.println("Current Calendar Date: " + cal.getTime());

      // use clear method to set all field values and time value as undefined.
      cal.clear();

      // print the result
      System.out.println("The calendar shows : " + cal.getTime());
   }
}

Let us compile and run the above program, this will produce the following result −

Current Calendar Date: Sat May 05 15:31:36 EEST 2012
The calendar shows : Thu Jan 01 00:00:00 EET 1970
java_util_calendar.htm
Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements