The computeTime() method in Calendar class is used for the conversion operation of the current calendar field values in fields[] to the millisecond time value time.
Syntax:
protected abstract void computeTime()
Parameters: The method does not take any parameters.
Return Value: The method does not return any value.
Below programs illustrate the working of computeTime() Method of Calendar class:
Example 1:
import java.util.*;
public class CalendarClassDemo
extends GregorianCalendar {
public static void main(String args[])
{
CalendarClassDemo calndr = new CalendarClassDemo();
System.out.println( "The Current "
+ "date is: " + calndr.getTime());
calndr.clear();
calndr.set(GregorianCalendar.YEAR, 2016 );
calndr.computeTime();
System.out.println( "The recent"
+ " date is: " + calndr.getTime());
}
}
|
Output:
The Current date is: Wed Feb 13 16:27:12 UTC 2019
The recent date is: Fri Jan 01 00:00:00 UTC 2016
Example 2:
import java.util.*;
public class CalendarClassDemo
extends GregorianCalendar {
public static void main(String args[])
{
CalendarClassDemo calndr = new CalendarClassDemo();
System.out.println( "The Current "
+ "date is: " + calndr.getTime());
calndr.clear();
calndr.set(GregorianCalendar.YEAR, 2000 );
calndr.computeTime();
System.out.println( "The recent"
+ " date is: " + calndr.getTime());
}
}
|
Output:
The Current date is: Wed Feb 13 16:27:15 UTC 2019
The recent date is: Sat Jan 01 00:00:00 UTC 2000
Reference: https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#computeTime()
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
14 Feb, 2019
Like Article
Save Article