Java Calendar.clear(int field)
Syntax
Calendar.clear(int field) has the following syntax.
public final void clear(int field)
Example
In the following code shows how to use Calendar.clear(int field) method.
//from w w w .j a va 2 s.co m
import java.util.Calendar;
public class Main {
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
// display the current date and time
System.out.println("Current Calendar Date: " + cal.getTime());
// use clear method to set year as undefined.
cal.clear(Calendar.YEAR);
// print the result
System.out.println("The calendar shows : " + cal.getTime());
// use clear method to set month as undefined.
cal.clear(Calendar.MONTH);
System.out.println("The calendar shows : " + cal.getTime());
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.util »
Java Tutorial »
java.util »