Reputation: 2713
How can I increase by day a date object? being careful of the month.
Upvotes: 1
Views: 150
Reputation: 23265
Depends on what you mean by "increase by a day". If you mean "increase by exactly 24 hours", then:
new Date(date.getTime() + 24*60*60*1000);
If you want to correct for the fact that not all days are 24 hours (daylight savings switchover days, for example), see the other answers.
Upvotes: 5
Reputation: 114777
This is terribly difficult and that's why we should use Calendar
for that. Otherwise you'll have to handle the different month lengths and leap years. The Calendar
implementation can do that already.
Upvotes: 2
Reputation: 347204
That's a job for the Calendar class.
Basically
Calendar cal = Calendar.getInstance();
cal.setTime(myDate);
cal.add(Calendar.DATE, 1);
myDaye = cal.getTime();
If you're serious about Date/Time manipulation, check out Joda-Time
Upvotes: 4