I have this Java Date
"Fri Oct 26 19:45:00 GMT+02:00 2018"
. How to get the day after that day? So I need this: "Sa Oct 27 19:45:00 GMT+02:00 2018"
.
How to achieve this?
Asked
Active
Viewed 165 times
0

marcelo.wdrb
- 2,041
- 2
- 10
- 16
1 Answers
4
long ms = yourDate.getTime();
Calendar c = Calendar.getInstance();
c.setTimeInMillis(ms);
c.add(Calendar.DATE, 1);
long nextDayInMillis = c.getTimeInMillis();
Date nextDate=new Date(nextDayInMillis);

slartidan
- 20,403
- 15
- 83
- 131

Vyacheslav
- 26,359
- 19
- 112
- 194
-
You can use `setTiime(yourDate)` instead of `setTimeInMillis(yourDate.getTime())`. See also the duplicated question https://stackoverflow.com/questions/1005523/how-to-add-one-day-to-a-date – slartidan Oct 25 '18 at 08:19
-
@slartidan that's much easier to write this answer instead of search this duplicated question on the internet. And of course, you can mark it as a duplicate. – Vyacheslav Oct 25 '18 at 08:21
-
@Vyacheslav Ah okay, and to get the day in a week, for example, it would be `c.add(Calendar.DATE, 7);`? – marcelo.wdrb Oct 25 '18 at 08:30
-
@Vyacheslav Ok, when my logic is right that should work...But how to do this when I want to get the Day one month later? – marcelo.wdrb Oct 25 '18 at 09:07
-
@marcelo.wdrb, of course, you can. You can use the other constants. For your case use `c.add(Calendar.MONTH, 1);` – Vyacheslav Oct 25 '18 at 09:08
-
Marking a question as duplicate will help to create a growing overview of different possibilities with all their up- and downsides. It is usually much more helpful to link to an existing, great question, than to try to spontaneously come up with an answer. – slartidan Oct 25 '18 at 10:25