Assume currently the date is the 28th of May. If I call the following commands in order the output becomes
cal.add(Calendar.DATE, 1); // Day = 29
cal.add(Calendar.DATE, 1); // Day = 30
cal.add(Calendar.DATE, 1); // Day = 31
cal.add(Calendar.DATE, 1); // Day = 31
cal.add(Calendar.DATE, -1); // Day = 29
Why is this not jumping into the next month? And why is it stuck at the 31st (but when you minus one it jumps to 29)?
Calendar cal = Calendar. getInstance(); cal. add(Calendar. HOUR_OF_DAY, 24);
You can easily do this in two simple ways my friend. First one is:
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_MONTH, 1);
and the second one is:
Calendar cal = Calendar.getInstance();
cal.add(Calendar.HOUR_OF_DAY, 24);
I think you would like to find this thing. Thanks.
When you add 1 to the Calendar.DATE
field, it should increment the month as well when the end of the month is reached (31 in the case for May) so that you wrote doesn't make sense.
Debug it and make sure the day value is indeed what you think it is
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With