Java.util.Calendar.complete() Method



Description

The java.util.Calendar.complete() method fills 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.

Declaration

Following is the declaration for java.util.Calendar.complete() method

protected void complete()

Parameters

NA

Return Value

This method does not return any value.

Exception

NA

Example

The following example shows the usage of java.util.Calendar.complete() method.

package com.tutorialspoint;

import java.util.*;

public class CalendarDemo extends GregorianCalendar {
   public static void main(String[] args) {

      // create a new calendar
      CalendarDemo cal = new CalendarDemo();

      // print the current date
      System.out.println("The current date is : " + cal.getTime());

      // clear the calendar
      cal.clear();

      // set a new year and call complete()
      cal.set(GregorianCalendar.YEAR, 1998);
      cal.complete();

      // print the current date
      System.out.println("New date is : " + cal.getTime());
   }
}

Let us compile and run the above program, this will produce the following result −

The current date is : Thu Jun 21 15:32:48 EEST 2012
New date is : Thu Jan 01 00:00:00 EET 1998
java_util_calendar.htm
Advertisements