Java.util.Calendar.computeTime() Method

Advertisements


Description

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

Declaration

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

protected abstract void computeTime()

Parameters

  • NA

Return Value

This method does not return any value.

Exception

  • NA

Example

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

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 computeTime()
      cal.set(GregorianCalendar.YEAR, 1998);
      cal.computeTime();

      // 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:35:42 EEST 2012
New date is : Thu Jan 01 00:00:00 EET 1998



Advertisements
Advertisements