DateUtil.addDays(days, date) is there any addDays method in java to add days to a date? Provide me any solution for this that how to add days to date
Asked
Active
Viewed 4,379 times
1
-
3How exactly did this extremely poor question got 5 upvotes, even when originally mistagged with [java-ee] tag? – BalusC Dec 02 '13 at 03:24
3 Answers
2
JDK native date/time handling is pretty poor. The Joda Time library's DateTime
is better than java.util.Date
class for anything requiring manipulation:
DateTime dt = new DateTime();
DateTime twoDaysLater = dt.plusDays(2);
If you want to create a DateTime
from a java.util.Date
:
Date nativeDate = new Date();
DateTime dt = new DateTime(nativeDate);
If you need to convert back to a java.util.Date
:
Date date = dt.toDate();

joews
- 29,767
- 10
- 79
- 91
2
You can use calendar.
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Calendar c = Calendar.getInstance();
c.setTime(new Date()); // Now use today date.
c.add(Calendar.DATE, 5); // Adding 5 days
String output = sdf.format(c.getTime());
System.out.println(output);

dev
- 715
- 5
- 21