Write a Java Program to Add months to the current date


The program first creates a Calendar object using the getInstance() method, which returns a Calendar instance based on the current time zone and locale. It then calls the add() method on the Calendar object, passing in the Calendar.MONTH field and the value 5, which adds 5 months to the current date and time. Finally, the program prints out the resulting date and time using the getTime() method of the Calendar object, which returns a Date object representing the current date and time.

Source Code

import java.util.*;
public class Add_Months
{
	public static void main(String[] args)
	{
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.MONTH, 5);
		System.out.println("Date After 5 Months : " + cal.getTime());
	}
}

Output

Date After 5 Months : Wed May 17 14:25:49 IST 2023

Example Programs