Online Java Compiler By
JavaTpoint.com
import java.util.Calendar; public class CalendaraddExample1 { public static void main(String[] args) { // create a new calendar Calendar cal = (Calendar) Calendar.getInstance(); // print the current date and time System.out.println("" + cal.getTime()); // add 9 years cal.add((Calendar.YEAR), 9); // print the modified date and time System.out.println("" + cal.getTime()); } }
Output