Java 在 Joda-Time DateTime 中添加一天
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16461361/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Add one day into Joda-Time DateTime
提问by user1156041
I have date Wed May 08 00:00:00 GMT+06:30 2013
. I add one day into it by using Joda-TimeDateTimelike this.
我有约会Wed May 08 00:00:00 GMT+06:30 2013
。我像这样使用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
. The joda date time didn't add one day. I haven't found any error.
当我打印 dateTime 时,我得到了这个 date 2013-05-08T00:00:00.000+06:30
。joda 日期时间没有增加一天。我没有发现任何错误。
Thanks
谢谢
采纳答案by Don Roby
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.
该plusDays
方法不是突变器。它返回给定DateTime
对象的副本,并进行更改,而不是更改给定对象。
If you want to actually change the variable dateTime
value, you'll need:
如果要实际更改变dateTime
量值,则需要:
DateTime dateTime = new DateTime(date);
dateTime = dateTime.plusDays(1);
回答by Ilya
If you want add days to current date time instance, use MutableDateTime
如果要将天数添加到当前日期时间实例,请使用MutableDateTime
MutableDateTime dateTime = new MutableDateTime(date);
dateTime.addDays(1);