Home »
Java programming language
Java Calendar complete() Method with Example
Calendar Class complete() method: Here, we are going to learn about the complete() method of Calendar Class with its syntax and example.
Submitted by Preeti Jain, on January 23, 2020
Calendar Class complete() method
- complete() method is available in java.util package.
- complete() method is used to fills in any non-set fields in the calendar fields.
- complete() method is a non-static method, it is accessible with the class object and if we try to access the method with the class name then we will get an error.
- complete() method does not throw an exception at the time of filling in an unset field.
Syntax:
protected void complete();
Parameter(s):
- It does not accept any parameter.
Return value:
The return type of the method is void, it returns nothing.
Example:
// Java Program to demonstrate the example of
// void complete() method of Calendar
import java.util.*;
public class CompleteOfCalendar extends GregorianCalendar {
public static void main(String[] args) {
// Instantiating a Calendar object
CompleteOfCalendar ca = new CompleteOfCalendar();
// Display current calendar
System.out.println("ca : " + ca.getTime());
// By using clear(int fi) method to set the
// field unset
ca.clear(GregorianCalendar.MONTH);
// Display calendar
System.out.println("ca.clear(GregorianCalendar.MONTH): " + ca.getTime());
ca.set(GregorianCalendar.MONTH, 6);
ca.complete();
// Display calendar
System.out.println("ca.set(GregorianCalendar.MONTH,6): " + ca.getTime());
}
}
Output
ca : Thu Jan 23 11:58:23 GMT 2020
ca.clear(GregorianCalendar.MONTH): Thu Jan 23 11:58:23 GMT 2020
ca.set(GregorianCalendar.MONTH,6): Thu Jul 23 11:58:23 GMT 2020