[英]How can I set a specific date into a Joda Time DateTime object?
I am pretty new in Joda Time and I have the following doubt:我是Joda Time 的新手,我有以下疑问:
I have simply created a new empty DateTime
object, in this way:我只是通过这种方式创建了一个新的空
DateTime
对象:
DateTime dataMovimentoFittizio = new DateTime();
My problem is that is seems to me that then I can't set the year, month and day for this object.我的问题是,在我看来,我无法为此对象设置年、月和日。
How can I correctly set a specific date into this object?如何正确地将特定日期设置到此对象中?
The Joda-Time classes mostly use immutable objects , designed to not be changed after instantiation. Joda-Time 类主要使用不可变对象,设计为在实例化后不会更改。
Use methods to instantiate new objects based partially on the values in the existing object.使用方法部分基于现有对象中的值来实例化新对象。
The Joda-Time project is now in maintenance mode, and advises migrating to the java.time classes. Joda-Time 项目现在处于维护模式,并建议迁移到 java.time 类。
The java.time classes strictly use immutable objects . java.time 类严格使用不可变对象。
LocalDate
For a date-only value without time of day and without time zone.对于没有时间和时区的仅日期值。 Use
LocalDate
.使用
LocalDate
。
LocalDate ld = LocalDate.of( 2016 , 1 , 23 ); // January 23, 2016
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.