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