从ISO8601日期时间字符串中提取时区 [英] Extract timezone from ISO8601 date time string

查看:368
本文介绍了从ISO8601日期时间字符串中提取时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从Java 8的ISO-8601日期字符串中提取时区。

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

例如:

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

谢谢。

推荐答案

使用 ZonedDateTime

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

获取 ZoneId

您也可以使用 getOffset()获取 ZoneOffset ,如果您需要以数字形式访问时区偏移量,则更方便。

Alternatively you can use getOffset() to obtain ZoneOffset,which is more handy if you need to access the timezone offset in a numeric form.

这篇关于从ISO8601日期时间字符串中提取时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆