How to add or subtract datetime in java with examples

Here we will learn how to add or subtract date time from given date.

Here we will use Calendar class from java.util package. It is an abstract class which provided method for manipulating the calendar field. We will use add(int field, int amount) method from this class. Which can be used to adds or subtracts the specified amount of time to the given calendar field, based on the calendar’s rules.

field is the calendar field.

amount is  the amount of date or time to be added/subtract to the field.

 

Output would be

 

 

About the author

J Singh

Main brain behind this blog/QnA site. She has written all these article as per her personal experience. She has published it mainly to help beginners. These articles might have some problems. So bear with her and let her know if you find any problem in any of the article.

3 Comments

Leave a Comment