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;
-
- Calendar now = Calendar.getInstance();
-
- System.out.println("Current date : " + now.get(Calendar.DATE) + "-" + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.YEAR));
-
- second = now.get(Calendar.SECOND);
- minute = now.get(Calendar.MINUTE);
- hour = now.get(Calendar.HOUR);
- System.out.println("Current time is " + hour + " : " + minute + " : " + second);
-
- 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));
-
- 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