Java Date Time - Java Calendar.complete()








Syntax

Calendar.complete() has the following syntax.

protected void complete()

Example

In the following code shows how to use Calendar.complete() method.

// w  w  w. j  ava  2s.c  om

import java.util.GregorianCalendar;

public class Main extends GregorianCalendar {

   public static void main(String[] args) {

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

      // 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());

   }
}

The code above generates the following result.