![]() |
VOOZH | about |
In Java, You can add the time to a Date object and it can be part of the java.util.Calendar package and another approach be used to newer java.time package. I can explain both approaches adding the time to a Date in Java programming. In this article, we are going to learn, how to add time to date in Java.
There are two methods to add time to date in Java:
Step-by-Step implementation:
Original date: Wed Feb 28 06:23:48 UTC 2024 Modified date: Wed Feb 28 07:23:48 UTC 2024
Explanation of the above Program:
In the above program is the example of the implementation of the adding time to date in java. In this example, We can create the instance of the calendar then set the time Date() method after that adding one hour after that get the time using calendar instance then print the original date and modified date.
Step-by-Step implementation:
Original date: Wed Feb 28 06:39:00 UTC 2024 Modified date: Wed Feb 28 07:39:00 UTC 2024
Explanation of the above Program:
In the above program is the example of the implementation to add time to a date using java.time package. In this example, We can create the instance of the LocalTime using now method to set the present after that add one hour using a method then convert into the date format using atZone takes the parameters of the system defaults converts into the date format.