Java Calendar - complete() Method
The java.util.Calendar.complete() method is used to fill in any unset fields in the calendar fields. First, the computeTime() method is called if the time value (millisecond offset from the Epoch) has not been calculated from calendar field values. Then, the computeFields() method is called to calculate all calendar field values.
Syntax
protected void complete()
Parameters
No parameter is required.
Return Value
void type.
Exception
NA.
Example:
In the example below, the java.util.Calendar.complete() method is used to fill in any unset fields in the given calendar fields.
import java.util.*; public class MyClass extends GregorianCalendar { public static void main(String[] args) { //creating Calendars MyClass Cal = new MyClass(); //printing the calendar System.out.println("The Calendar is: " + Cal.getTime()); //clear the calendar Cal.clear(); //set 1998 as a new year and call complete() Cal.set(GregorianCalendar.YEAR, 1998); Cal.complete(); //printing the calendar System.out.println("New Calendar is: " + Cal.getTime()); } }
The output of the above code will be:
The Calendar is: Sat Sep 12 06:45:29 UTC 2020 New Calendar is: Thu Jan 01 00:00:00 UTC 1998
❮ Java.util - Calendar