Java将utc时间转换为本地时间

时间:2017-05-24 08:09:06

标签: java

嗨我有一个问题:从服务器我得到一个时间,它看起来像这样:

"date":"2017-05-24T07:56:22Z"

但现在我当地的时间是09:56:22如何转换呢?

1 个答案:

答案 0 :(得分:2)

首先,您需要解析日期,例如:

Instant instant = Instant.parse("2017-05-24T07:56:22Z");

假设您的时区设置正确,您可以直接使用:

LocalTime localTime = instant.atZone(ZoneId.systemDefault()).toLocalTime();

如果您想使用特定时区而不是系统默认时区:

LocalTime localTime = instant.atZone(ZoneId.of("Europe/London")).toLocalTime();