java - Jodatime 的 DateTime 的默认日期时区为 UTC

标签 java jodatime

我目前正在使用当前惯用语创建 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/

相关文章:

java - 如何从 32 字节原始私钥获取 java.security.PrivateKey ? (Secp256k1算法)

java - 如何使用 Spring Boot Gradle 插件和 bootJar 任务有条件地排除 java 文件?

java - wicket-auth-roles 和 spring-security-cas-client 之间的身份验证集成问题

java - 使用 lucene SynonymFilter 时无法对单词进行标记

java - 如何在 JPA (eclipselink) 中使用 joda 时间?

java - JodaTime DateTime 和使用 AM/PM 处理语言环境

java - 用Java获取两个工作日之间的分钟数

java - joda-time-2.2 将 LocalDateTime 转换为 java.sql.Timestamp

java - 如何将 Maven 指向 Java 源代码依赖项?

java - 如何找到任意日期最近的工作日?