Java.util.GregorianCalendar.computeTime() Method



Description

The java.util.GregorianCalendar.computeTime() method converts calendar field values to the time value (millisecond offset from the Epoch).

Declaration

Following is the declaration for java.util.GregorianCalendar.computeTime() method

protected void computeTime()

Parameters

NA

Return Value

This method does not return a value.

Exception

NA

Example

The following example shows the usage of java.util.GregorianCalendar.computeTime() method.

package com.tutorialspoint;

import java.util.*;

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

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

      // print the current date and time
      System.out.println("" + cal.getTime());

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

      // compute time and print the date
      cal.computeTime();
      System.out.println("" + cal.getTime());
   }
}

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

Wed Jun 20 17:25:58 EEST 2012
Sat Jun 20 17:25:58 EEST 1992
Sat Jun 20 17:25:58 EEST 1992
java_util_gregoriancalendar.htm
Advertisements