更新时间:2023-02-18 23:10:55
Joda-Time 项目,现在位于维护模式,建议迁移到 java.time 类。
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.