Java Date Time - Java Calendar.computeTime()








Syntax

Calendar.computeTime() has the following syntax.

protected abstract void computeTime()

Example

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

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


import java.util.GregorianCalendar;

public class Main extends GregorianCalendar {

   public static void main(String[] args) {

      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 computeTime()
      cal.set(GregorianCalendar.YEAR, 2013);
      cal.computeTime();

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

   }
}

The code above generates the following result.