从java.util.TimeZone转换为org.joda.DateTimeZone [英] Converting from java.util.TimeZone to org.joda.DateTimeZone
问题描述
在Java中如何将 java.util.TimeZone
的实例转换为 org.joda.DateTimeZone
How is it possible in Java to convert an instance of java.util.TimeZone
to org.joda.DateTimeZone
and keeping the daylight saving time?
推荐答案
Joda-Time处于维护模式
Joda-Time 项目,现在位于维护模式,建议迁移到 java.time 类。
Joda-Time in maintenance-mode
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
java.util.TimeZone
是 java.time.ZoneId
java.time.ZoneOffset
。
您应该避免使用旧的旧式日期时间类。但是,如有必要,您可以与java.time类型进行转换。查看添加到旧类中的新方法。您可以在 TimeZone
和 ZoneId
之间切换。
You should avoid the old legacy date-time classes. But if necessary, you can convert to/from the java.time types. Look to new methods added to the old classes. You can move between TimeZone
and ZoneId
.
java.util.TimeZone tz = java.util.TimeZone.getTimeZone( myZoneId );
…和…
java.time.ZoneId z = myLegacyTimeZone.toZoneId();
如果您要查找相对于UTC的偏移量或夏令时(DST)信息区域,请查看 ZoneRules
类。搜索堆栈溢出以获取更多讨论和示例,或者编辑问题以描述有关您的目标的更多信息。
If you are looking for the offset-from-UTC or Daylight Saving Time (DST) info for the zone, look at the ZoneRules
class. Search Stack Overflow for more discussion and examples on that, or edit your Question to describe more about your goal.
这篇关于从java.util.TimeZone转换为org.joda.DateTimeZone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!