Calendar complete() Method in Java with Examples
The complete() method in Calendar class is used to fill any unset fields of the calendar fields. It follows the following process of completion:
- At first, if the time value has not been calculated, the computeTime() method is called to calculate it from calendar field values.
- Second, to calculate all the calendar field values the computeFields() method is used.
Syntax:
protected void complete()
Parameters: The method does not take any parameters.
Return Value: The method does not return any value.
Below programs illustrate the working of complete() Method of Calendar class:
Example 1:
import java.util.*;
public class CalendarClassDemo
extends GregorianCalendar {
public static void main(String args[])
{
CalendarClassDemo calndr = new CalendarClassDemo();
System.out.println( "The Current "
+ "date is: " + calndr.getTime());
calndr.clear();
calndr.set(GregorianCalendar.YEAR, 2008 );
calndr.complete();
System.out.println( "The new"
+ " date is: " + calndr.getTime());
}
}
|
Output:
The Current date is: Wed Feb 13 15:39:33 UTC 2019
The new date is: Tue Jan 01 00:00:00 UTC 2008
Example 2:
import java.util.*;
public class CalendarClassDemo
extends GregorianCalendar {
public static void main(String args[])
{
CalendarClassDemo calndr = new CalendarClassDemo();
System.out.println( "The Current "
+ "date is: " + calndr.getTime());
calndr.clear();
calndr.set(GregorianCalendar.YEAR, 1996 );
calndr.complete();
System.out.println( "The new"
+ " date is: " + calndr.getTime());
}
}
|
Output:
The Current date is: Wed Feb 13 15:39:36 UTC 2019
The new date is: Mon Jan 01 00:00:00 UTC 1996
Reference: https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#complete()
Last Updated :
14 Feb, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...