我目前正在使用当前的习惯用法创建UTC DateTime对象
DateTime now = new DateTime(DateTimeZone.UTC);
Run Code Online (Sandbox Code Playgroud)
有没有办法默认所以我可以使用默认构造函数创建基于UTC的DateTime对象,所以它更隐含?
DateTime now = new DateTime();
Run Code Online (Sandbox Code Playgroud)
dac*_*cwe 70
如果您只想为joda时间设置默认时区,请使用DateTimeZone.setDefault
.
如果你想改变整个jvm使用TimeZone.setDefault
方法的时区.请务必尽早设置它,因为它可以通过joda时间缓存..引自DateTimeZone.getDefault:
默认时区源自系统属性user.timezone.如果该值为null或不是有效标识符,则转换JDK TimeZone缺省值.如果失败,则使用UTC.
jta*_*orn 15
如果你真的关心额外的字符,那么只需创建一个辅助方法:
public static DateTime newUTCDateTime() {
return new DateTime(DateTimeZone.UTC);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
69399 次 |
最近记录: |