Java GregorianCalendar - computeFields() Method
The java.util.GregorianCalendar.computeFields() method is used to convert the time value (millisecond offset from the Epoch) to calendar field values. The time is not recomputed first; to recompute the time, then the fields, call the complete method.
Syntax
protected void computeFields()
Parameters
No parameter is required.
Return Value
void type.
Exception
NA.
Example:
In the example below, the java.util.GregorianCalendar.computeFields() method is used to convert the time value (millisecond offset from the Epoch) to given calendar field values.
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(GregorianCalendar.YEAR, 2015); System.out.println("The new date is: " + Cal.getTime()); //compute field 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: Tue Sep 08 07:07:04 UTC 2020 The new date is: Tue Sep 08 07:07:04 UTC 2015 The new date is: Tue Sep 08 07:07:04 UTC 2015
❮ Java.util - GregorianCalendar