Java Date Time - Java Calendar.computeFields()








Syntax

Calendar.computeFields() has the following syntax.

protected abstract void computeFields()

Example

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

/*from   w w  w.  j  av a  2  s.c om*/

import java.util.GregorianCalendar;

public class Main extends GregorianCalendar {

   public static void main(String[] args) {

      Main cal = new Main();


      // clear the calendar
      cal.clear();

      // set a new year and call computeFields()
      cal.set(GregorianCalendar.YEAR, 2013);
      cal.computeFields();

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

   }
}

The code above generates the following result.