Javatpoint Logo
Javatpoint Logo

How to Change the Day in The Date Using Java?

The Java Calendar class (java.util.Calendar) is a very helpful and practical class for manipulating dates and times in Java. Here, I'll show you how to change the date and time using the calendar class.

Get today's date and time using a calendar() class method.

Change the date or time on a calendar.

This complete source code demonstrates how to change the date and time in Java.

// File name: DateTimeChanging.java

Output:

Present Date Time is : 2023/01/14 18:15:26
 Adding one day to the present date : 2023/01/15 18:15:26
 Adding one month to the present date : 2023/02/14 18:15:26
 Adding one year to the present date : 2024/01/14 18:15:26
 Adding one hour to the present date : 2023/01/14 19:15:26
 Adding one minute to the present date : 2023/01/14 18:16:26
 Adding one second to the present date : 2023/01/14 18:15:27
 Subtracting one day from the present date : 2023/01/13 18:15:26
 Subtracting one month from the present date : 2022/12/14 18:15:26
 Subtracting one year from the present date : 2022/01/14 18:15:26
 Subtracting one hour from present date : 2023/01/14 17:15:26
 Subtracting one minute from the present date : 2023/01/14 18:14:26
 Subtracting one second from the present date : 2023/01/14 18:15:25






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA