This question already has an answer here:
How do I add x days to a date in Java?
For example, my date is (dd/mm/yyyy) = 01/01/2012
Adding 5 days, the output should be 06/01/2012
.
This question already has an answer here:
How do I add x days to a date in Java?
For example, my date is (dd/mm/yyyy) = 01/01/2012
Adding 5 days, the output should be 06/01/2012
.
If you're using Joda-Time (and there are lots of good reasons to - a simple, intuitive API and thread-safety) then you can do this trivially:
to give 5 days from today, for example.
Simple, without any other API:
To add 8 days:
You can also substract days like
Calendar.add(Calendar.DAY_OF_MONTH, -5);
Here is some simple code to give output as
currentdate
+D days
=some 'x' date
(future date):java.time
With the Java 8 Date and Time API you can use the
LocalDate
class.See the Oracle Tutorial.