Online Java Compiler By
JavaTpoint.com
import java.util.GregorianCalendar; public class CalendarComputefieldExample4 extends GregorianCalendar{ public static void main(String[] args) { // create a new calendar CalendarComputefieldExample4 cal = new CalendarComputefieldExample4(); // 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.HOUR, 22); cal.set(GregorianCalendar.SECOND, 400); cal.set(GregorianCalendar.MINUTE, 70); System.out.println("New date is : " + cal.getTime()); cal.computeFields(); // print the current date System.out.println("New date is : " + cal.getTime()); } }
Output