Java Date Time - Java GregorianCalendar .computeTime ()








Syntax

GregorianCalendar.computeTime() has the following syntax.

protected void computeTime()

Example

In the following code shows how to use GregorianCalendar.computeTime() method.

/*from w  w w  .  j  a v  a  2  s .  c o  m*/

import java.util.*;

public class Main extends GregorianCalendar {

   public static void main(String[] args) {


      Main cal = new Main();


      // set a new year
      cal.set(GregorianCalendar.YEAR, 1992);
      System.out.println(cal.getTime());

      // compute fields and print the date
      cal.computeFields();
      System.out.println(cal.getTime());
   }
}

The code above generates the following result.