Add One Day to Joda-Time DateTime

I have a date Wed May 08 00:00:00 GMT+06:30 2013 . I add one day to it using Joda-Time DateTime .

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

When I print DateTime, I got this date 2013-05-08T00:00:00.000+06:30 . Jod's date time did not add a single day. I did not find any errors.

thank

+63
java datetime jodatime
May 9 '13 at 12:04
source share
2 answers

The plusDays method plusDays not a mutator. It returns a copy of this DateTime object with the change, not the change, of the given object.

If you want to change the value of the DateTime variable, you need to:

 DateTime dateTime = new DateTime(date); dateTime = dateTime.plusDays(1); 
+129
May 09 '13 at 12:08
source share

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

 MutableDateTime dateTime = new MutableDateTime(date); dateTime.addDays(1); 
+28
May 10 '13 at 6:49
source share



All Articles