Add one day into Joda-Time DateTime

JavaDatetimeJodatime

Java Problem Overview


I have date Wed May 08 00:00:00 GMT+06:30 2013. I add one day into it by using Joda-Time DateTime like this.

DateTime dateTime = new DateTime(date);
dateTime.plusDays(1);

When I print dateTime, I got this date 2013-05-08T00:00:00.000+06:30. The joda date time didn't add one day. I haven't found any error.

Thanks

Java Solutions


Solution 1 - Java

The plusDays method is not a mutator. It returns a copy of the given DateTime object with the change made rather than changing the given object.

If you want to actually change the variable dateTime value, you'll need:

DateTime dateTime = new DateTime(date);
dateTime = dateTime.plusDays(1);

Solution 2 - Java

If you want add days to current date time instance, use MutableDateTime

MutableDateTime dateTime = new MutableDateTime(date);  
dateTime.addDays(1);

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1156041View Question on Stackoverflow
Solution 1 - JavaDon RobyView Answer on Stackoverflow
Solution 2 - JavaIlyaView Answer on Stackoverflow