简体   繁体   English

从ISO8601日期时间字符串中提取时区

[英]Extract timezone from ISO8601 date time string

How to extract time zone from ISO-8601 date string in Java 8. 如何在Java 8中从ISO-8601日期字符串中提取时区。

eg: 例如:

   String timestamp1 = "2014-02-15T01:02:03Z" ;
   String timestamp2 = "2017-10-27T16:22:27.605-05:30";

Thanks. 谢谢。

Use ZonedDateTime : 使用ZonedDateTime

ZonedDateTime.parse("2017-10-27T16:22:27.605-05:30").getZone()

to get an instance of ZoneId . 获取ZoneId的实例。

Alternatively you can use getOffset() to obtain ZoneOffset ,which is more handy if you need to access the timezone offset in a numeric form. 或者,您可以使用getOffset()获得ZoneOffset ,如果您需要以数字形式访问时区偏移量,则此方法更加方便。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM