Scala中的java.time - 从时区获取UTC偏移量

时间:2015-06-12 19:24:03

标签: scala utc timezone-offset

我正在尝试使用java.time从时区(亚洲/亚丁)获取UTC偏移量。

请参阅以下错误:

scala> val a = ZoneId.of("Asia/Aden")
a: java.time.ZoneId = Asia/Aden

scala> ZoneOffset.of(a)
<console>:13: error: type mismatch;
 found   : java.time.ZoneId
 required: String
              ZoneOffset.of(a)
                            ^

scala> val as = a.getId
as: String = Asia/Aden

scala> ZoneOffset.of(as)
java.time.DateTimeException: Invalid ID for ZoneOffset, non numeric characters found: Asia/Aden
  at java.time.ZoneOffset.parseNumber(ZoneOffset.java:269)
  at java.time.ZoneOffset.of(ZoneOffset.java:236)
  ... 33 elided

1 个答案:

答案 0 :(得分:1)

scala> val b = ZonedDateTime.now(ZoneId.of("Asia/Aden")).getOffset
b: java.time.ZoneOffset = +03:00

Wikipedia

CC  Coordinates     TZ  Comments    UTC offset  UTC DST offset
YE  +1245+04512     Asia/Aden       +03:00      +03:00