Here we will write an example to add or substract days in current date and time values with java Calendar class.
Source Code
package com.beginner.examples;
import java.util.Calendar;
public class ASDaysExample {
public static void main(String[] args){
//get calendar
Calendar now = Calendar.getInstance();
System.out.println(now.get(Calendar.DATE));
//days add 1
now.add(Calendar.DATE, 1);
System.out.println(now.get(Calendar.DATE));
//days subtract 1
now.add(Calendar.DATE, -1);
System.out.println(now.get(Calendar.DATE));
}
}
Output:
30
31
30
References
Imported packages in Java documentation: