Here the Java code that display the current date & time as well as by adding and subtracting the days from the current date.
import java.util.Calendar;
public class Table {
public static void main(String[] args) {
int second, minute, hour;
//create Calendar instance
Calendar now = Calendar.getInstance();
//display current date (dd-mm-yyyy)
System.out.println("Current date : " + now.get(Calendar.DATE) + "-" + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.YEAR));
//display current time
second = now.get(Calendar.SECOND);
minute = now.get(Calendar.MINUTE);
hour = now.get(Calendar.HOUR);
System.out.println("Current time is " + hour + " : " + minute + " : " + second);
//add days to current date
now.add(Calendar.DATE, 1);
System.out.println("date after one day : " + now.get(Calendar.DATE) + "-" + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.YEAR));
//subtract days from current date
now = Calendar.getInstance();
now.add(Calendar.DATE, -10);
System.out.println("date before 10 days : " + now.get(Calendar.DATE) + "-" + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.YEAR));
}
}Thank you, keep learning and sharing
