Extract timezone from ISO8601 date time string

2019-08-12 05:15发布

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条回答
一夜七次
2楼-- · 2019-08-12 05:55

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.

查看更多
登录 后发表回答