Java Utility Library

Java Calendar - computeTime() Method



The java.util.Calendar.computeTime() method is used to convert the current calendar field values in fields[] to the millisecond time value time.

Syntax

protected abstract void computeTime()

Parameters

No parameter is required.

Return Value

void type.

Exception

NA.

Example:

In the example below, the java.util.Calendar.computeTime() method is used to convert the current calendar field values to the millisecond time value.

import java.util.*;

public class MyClass extends GregorianCalendar {
  public static void main(String[] args) {
    //creating a Calendar object
    MyClass Cal = new MyClass();

    //printing the current date
    System.out.println("The current date is: " + Cal.getTime());

    //set to a new year
    Cal.set(Calendar.YEAR, 2015);
    System.out.println("The new date is: " + Cal.getTime());

    //compute time and print date
    Cal.computeFields();
    System.out.println("The new date is: " + Cal.getTime());
  }
}

The output of the above code will be:

The current date is: Thu Sep 10 05:41:46 UTC 2020
The new date is: Thu Sep 10 05:41:46 UTC 2015
The new date is: Thu Sep 10 05:41:46 UTC 2015

❮ Java.util - Calendar