Extract timezone from ISO8601 date time string

牧云@^-^@ 提交于 2019-12-24 06:00:36

问题


How to extract time zone from ISO-8601 date string in Java 8.

e.g:

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

Thanks.


回答1:


Use ZonedDateTime:

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

to get an instance of 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.



来源:https://stackoverflow.com/questions/46216099/extract-timezone-from-iso8601-date-time-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!