Write a Java Program to Add days to the current date


This Java program adds 3 days to the current date and time using the Calendar class. 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.DATE field and the value 3, which adds 3 days 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_Days
{
	public static void main(String[] args)
	{
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.DATE, 3);
		System.out.println("Date After 3 Days : " + cal.getTime());
	}
}

Output

Date After 3 Days : Tue Dec 20 14:29:00 IST 2022

Example Programs