Java.util.GregorianCalendar.computeFields() Method
Description
The java.util.GregorianCalendar.computeFields() method converts 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.
Declaration
Following is the declaration for java.util.GregorianCalendar.computeFields() method
protected void computeFields()
Parameters
NA
Return Value
This method does not return a value.
Exception
NA
Example
The following example shows the usage of java.util.GregorianCalendar.computeFields() 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 fields and print the date
cal.computeFields();
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