Code Base

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

V Gautam

Me & Jayshree Singh. Main brain behind this blog/QnA site. We have written all these article as per my personal experience. I have published it mainly to help. These articles might have some problems. So bear with me and let me know if you find any problem in any of the article. You can find me on


Leave a Comment