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.
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()); } }
Date After 5 Months : Wed May 17 14:25:49 IST 2023
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions