The Wayback Machine - https://web.archive.org/web/20241004181037/https://www.geeksforgeeks.org/calendar-complete-method-in-java-with-examples/
Open In App

Calendar complete() Method in Java with Examples

Last Updated : 14 Feb, 2019
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The complete() method in Calendar class is used to fill any unset fields of the calendar fields. It follows the following process of completion:

  1. At first, if the time value has not been calculated, the computeTime() method is called to calculate it from calendar field values.
  2. 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:




// Java Code to illustrate
// complete() Method
  
import java.util.*;
  
public class CalendarClassDemo
    extends GregorianCalendar {
    public static void main(String args[])
    {
        // Creating calendar object
        CalendarClassDemo calndr = new CalendarClassDemo();
  
        // Displaying the current date
        System.out.println("The Current "
                           + "date is: " + calndr.getTime());
  
        // Clearing the calendar
        calndr.clear();
  
        // Set a new year and call
        // complete()
        calndr.set(GregorianCalendar.YEAR, 2008);
        calndr.complete();
  
        // Displaying the current date
        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:




// Java Code to illustrate
// complete() Method
  
import java.util.*;
  
public class CalendarClassDemo
    extends GregorianCalendar {
    public static void main(String args[])
    {
        // Creating calendar object
        CalendarClassDemo calndr = new CalendarClassDemo();
  
        // Displaying the current date
        System.out.println("The Current "
                           + "date is: " + calndr.getTime());
  
        // Clearing the calendar
        calndr.clear();
  
        // Set a new year and call
        // complete()
        calndr.set(GregorianCalendar.YEAR, 1996);
        calndr.complete();
  
        // Displaying the current date
        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()



Similar Reads

Calendar clone() Method in Java with Examples
The clear() method in Calendar class is used to clone a calendar object. It basically creates a shallow copy of this object. Syntax: public Object clone() Parameters: The method does not take any parameters. Return Value: The method does not return any value. Below programs illustrate the working of clone() Method of Calendar class: Example 1: // J
2 min read
Calendar clear() Method in Java with Examples
The clear() method in Calendar class is used to set all the calendar field values and the time value of this Calendar undefined. Note: Implementation of calendar class may use default field values for date and time calculations. Syntax: public final void clear() Parameters: The method does not take any parameters. Return Value: The method does not
2 min read
Calendar add() Method in Java with Examples
The add() method of Calendar class present inside is used to add or subtract from the given calendar field(int field), a specific amount of time(int amt), based on the calendar's rules. Syntax: public abstract void add(int field, int amt) Parameters: The method takes two parameters: The field of the calendar on which the operation is to be performe
3 min read
Calendar toString() Method in Java with Examples
The toString() method in Calendar class is used to get the string representation of the Calendar object. This method in Calendar Class is just for debug process and not to be used as an operation. Syntax: public String toString() Parameters: The method does not take any parameters. Return Value: The method returns the String representation of the C
1 min read
Calendar compareTo() Method in Java with Examples
The add(Calendar Calendar2) method of Calendar class is used to compare the time values or the millisecond offsets of this Calendar object with the passed Calendar object. Syntax: public int compareTo(Calendar Calendar2) Parameters: The method takes one parameter Calendar2 of Calendar object type and refers to the object to be compared to this Cale
2 min read
Calendar computeTime() method in Java with Examples
The computeTime() method in Calendar class is used for the conversion operation of the current calendar field values in fields[] to the millisecond time value time. Syntax: protected abstract void computeTime() Parameters: The method does not take any parameters. Return Value: The method does not return any value. Below programs illustrate the work
2 min read
Calendar computeFields() method in Java with Examples
The computeFields() method in Calendar class is used for the conversion operation of the current millisecond time value time to calendar field values mentioned in the fields[]. Note: This allows syncing up the new time that is set for the calendar object with the calendar field values. Syntax: protected abstract void computeFields() Parameters: The
2 min read
Calendar get() method in Java with Examples
The get(int field_value) method of Calendar class is used to return the value of the given calendar field in the parameter. Syntax: public int get(int field) Parameters: The method takes one parameter field_value of integer type and refers to the calendar whose value is needed to be returned. Return Value: The method returns the value of the passed
2 min read
Calendar getActualMinimum() Method in Java with Examples
The getActualMinimum(int field_value) method of Calendar class is used to return the minimum value that the specified calendar field could have, based on the time value of this Calendar. Syntax: public int getActualMinimum(int field_value) Parameters: The method takes one parameter field_value of integer type and refers to the calendar whose minimu
2 min read
Calendar getActualMaximum() Method in Java with Examples
The getActualMaximum(int field_value) method of Calendar class is used to return the maximum value that the specified calendar field could have, based on the time value of this Calendar. Syntax: public int getActualMaximum(int field_value) Parameters: The method takes one parameter field_value of integer type and refers to the calendar whose maximu
2 min read
Calendar getAvailableLocales() Method in Java with Examples
The clear() method in Calendar class is used to return an array of all the locales available at the localized instances of the getInstance method of this class. Syntax: public static Locale[] getAvailableLocales() Parameters: The method does not take any parameters. Return Value: The method returns an array of all the locales for which the localize
2 min read
Calendar getDisplayName() Method in Java with Examples
The getDisplayName(int cal_field, int cal_style, Locale local) method of Calendar class is used to return the string representation of a calendar field(int cal_field) value in the given style(int cal_style) and locale(int local). Syntax: public String getDisplayName(int cal_field, int cal_style, Locale local) Parameters: The method takes three para
3 min read
Calendar getDisplayNames() Method in Java with Examples
The getDisplayNames(int cal_field, int cal_style, Locale local) method of Calendar class is used to return a map containing all the names of the calendar field(int cal_field) in the given style(int cal_style) and locale(Locale local) and their corresponding field values. Syntax: public Map getDisplayNames(int field, int style, Locale locale) Parame
2 min read
Calendar getFirstDayOfWeek() Method in Java with Examples
The getFirstDayOfWeek() method in Calendar class is used to return the first day of the week of this Calendar.Syntax: public int getFirstDayOfWeek() Parameters: The method does not take any parameters.Return Value: The method returns the first day of the week.Below programs illustrate the working of getFirstDayOfWeek() Method of Calendar class: Exa
1 min read
Calendar getGreatestMinimum() Method in Java with Examples
The getGreatestMinimum(int calndr_field) method in Calendar class is used to return the highest minimum value for the given calendar field(int calndr_field) of this Calendar instance. Syntax: public abstract int getGreatestMinimum(int calndr_field) Parameters: The method takes one parameter calndr_field that refers to the calendar field which is to
2 min read
Calendar getInstance() Method in Java with Examples
The getInstance() method in Calendar class is used to get a calendar using the current time zone and locale of the system. Syntax: public static Calendar getInstance() Parameters: The method does not take any parameters. Return Value: The method returns the calendar. Below program illustrates the working of getInstance() Method of Calendar class: E
1 min read
Calendar getLeastMaximum() method in Java with Examples
The getLeastMaximum(int calndr_field) method in Calendar class is used to return the lowest maximum value for the given calendar field(int calndr_field) of this Calendar instance. Syntax: public abstract int getLeastMaximum(int calndr_field) Parameters: The method takes one parameter calndr_field that refers to the calendar field which is to be ope
2 min read
Calendar getMaximum() method in Java with Examples
The getMaximum(int calndr_field) method in Calendar class is used to return the maximum value for the given calendar field(int calndr_field) of this Calendar instance. Syntax: public abstract int getMaximum(int calndr_field) Parameters: The method takes one parameter calndr_field that refers to the calendar field which is to be operated upon. Retur
2 min read
Calendar getMinimalDaysInFirstWeek() Method in Java with Examples
The getMinimalDaysInFirstWeek() method in Calendar class is used to return the minimal days that is required in the first week of the needed year.Syntax: public int getMinimalDaysInFirstWeek() Parameters: The method does not take any parameters.Return Value: The method returns the minimal days required in the first week of the following year.Below
1 min read
Calendar getMinimum() Method in Java with Examples
The getMinimum(int calndr_field) method in Calendar class is used to return the Minimum value for the given calendar field(int calndr_field) of this Calendar instance. Syntax: public abstract int getMinimum(int calndr_field) Parameters: The method takes one parameter calndr_field that refers to the calendar field which is to be operated upon. Retur
2 min read
Calendar getTimeInMillis() Method in Java with Examples
The getTimeInMillis() method in Calendar class is used to return the current time of this Calendar in Milliseconds.Syntax: public long getTimeInMillis() Parameters: The method does not take any parameters.Return Value: The method returns the current time of this Calendar in millisecond.Below programs illustrate the working of getTimeInMillis() Meth
2 min read
Calendar isLenient() Method in Java with Examples
The isLenient() method in Calendar class is used to know and understand whether the date and time interpretation of this Calendar is to be considered lenient or not.Syntax: public boolean isLenient() Parameters: The method does not take any parameters.Return Value: The method either returns True if the interpretation of this Calendar is lenient els
2 min read
Calendar hashCode() Method in Java with Examples
The hashCode() method in Calendar class is used to return the hash code for this Calendar Object.Syntax: public int hashCode() Parameters: The method does not take any parameters.Return Value: The method returns the hash code value for this calendar object..Below programs illustrate the working of hashCode() Method of Calendar class: Example 1: Jav
2 min read
Calendar getTime() Method in Java with Examples
The getTime() method in Calendar class is used to return an object resembling the Date that is represented by this Calendar's time value.Syntax: public final Date getTime() Parameters: The method does not take any parameters.Return Value: The method returns the Date, represented by this Calendar.Below programs illustrate the working of getTime() Me
2 min read
Calendar roll() Method in Java with Examples
The roll(int calndr_field, boolean up_down) method in Calendar class is used to operate on the passed calendar field by moving the passed field, up or down by a single unit of time. This involves addition or subtraction of the time field without changing the larger fields. Syntax: public abstract void roll(int calndr_field, boolean up_down) Paramet
2 min read
Calendar isSet() Method in Java with Examples
The isSet(int calndr_field) method in Calendar class is used to check whether the given calendar field has a value set or not. All the Cases for which the values have been set by the calculations of the internal field are triggered by a get method call. Syntax: public final boolean isSet(int calndr_field) Parameters: The method takes one parameter
2 min read
Calendar set() Method in Java with Examples
The set(int calndr_field, int new_val) method in Calendar class is used to set the calndr_field value to a new_val. The older field of this calendar get replaced by a new field. Syntax: public void set(int calndr_field, int new_val) Parameters: The method takes two parameters: calndr_field: This is of Calendar type and refers to the field of the ca
2 min read
Calendar setFirstDayOfWeek() Method in Java with Examples
The setFirstDayOfWeek(int day_val) method in Calendar class is used to set the first day of the week using the day_val in this Calendar. Syntax: public void set(int day_val) Parameters: The method takes one parameter day_val of integer type and refers to the first day of the week. Return Value: The method does not return any value. Below programs i
2 min read
Calendar setLenient() Method in Java with Examples
The setLenient(boolean leniency) method in Calendar class is used to specify whether the interpretation of the date and time is to be lenient or not. Syntax: public void setLenient(boolean leniency) Parameters: The method takes one parameter leniency of the boolean type that refers to the mode of the calendar. The boolean value true turns on the le
2 min read
Calendar internalGet() Method in Java with Examples
The internalGet(int calndr_field) method in Calendar class is used to return the value of the given calendar field as a parameter. Note: The operation does not involve any normalization or validation. Syntax: protected final int internalGet(int calndr_field) Parameters: The method takes one parameter calndr_field that refers to the calendar field w
2 min read
Practice Tags :