Java.util.Calendar.computeFields() Method


Advertisements


Description

The java.util.Calendar.computeFields() method converts the current millisecond time value time to calendar field values in fields[]. This allows syncing up with the calendar field values with a new time that is set for the calendar object.

Declaration

Following is the declaration for java.util.Calendar.computeFields() method

protected abstract void computeFields()

Parameters

NA

Return Value

This method does not return any value.

Exception

NA

Example

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

Live Demo
package com.tutorialspoint;

import java.util.*;

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

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

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

      // clear the calendar
      cal.clear();

      // set a new year and call computeFields()
      cal.set(GregorianCalendar.YEAR, 1998);
      cal.computeFields();

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

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

The current date is : Thu Jun 21 15:34:36 EEST 2012
New date is : Thu Jun 21 15:34:36 EEST 2012

java_util_calendar.htm


Advertisements
E-Books Store