
Write a JAVA program to add or subtract days in current date and time values using JAVA calendar class.

import java.util.Calendar;
public class AddSubtractDays {
public static void main(String[] args){
Calendar now = Calendar.getInstance();
System.out.println("Current date : " + (now.get(Calendar.DATE)) + "-"+ (now.get(Calendar.MONTH)+1) + "-" + now.get(Calendar.YEAR));
now.add(Calendar.DATE, 1);
System.out.println("date after adding days : " + (now.get(Calendar.DATE)) + "-" + (now.get(Calendar.MONTH)+1) + "-" + now.get(Calendar.YEAR));
Calendar now1 = Calendar.getInstance();
now1.add(Calendar.DATE, -1);
System.out.println("date after subtracting days : " + (now1.get(Calendar.DATE)) + "-" +(now.get(Calendar.MONTH)+1) + "-" + now1.get(Calendar.YEAR));
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.