Online Java Compiler By
JavaTpoint.com
import java.util.GregorianCalendar; public class CalendarComputefieldExample3 extends GregorianCalendar { public static void main(String[] args) { // create a new calendar CalendarComputefieldExample3 cal = new CalendarComputefieldExample3(); // 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.DAY_OF_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