我目前正在使用当前惯用语创建 UTC DateTime 对象
DateTime now = new DateTime(DateTimeZone.UTC);
有什么方法可以默认,所以我可以使用默认构造函数创建基于 UTC 的 DateTime 对象,这样它就更隐含了?
DateTime now = new DateTime();
最佳答案
如果您只想为 joda 时间设置默认时区,请使用 DateTimeZone.setDefault
.
如果您想更改整个 jvm 使用的时区,请使用 TimeZone.setDefault
方法。请务必尽早设置它,因为它可以被 joda time 缓存.. 引用自 DateTimeZone.getDefault :
The default time zone is derived from the system property user.timezone. If that is null or is not a valid identifier, then the value of the JDK TimeZone default is converted. If that fails, UTC is used.
关于java - Jodatime 的 DateTime 的默认日期时区为 UTC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9397715/