This question already has an answer here:
这个问题在这里已有答案:
- Java: How do you convert a UTC timestamp to local time? 3 answers
Java:如何将UTC时间戳转换为本地时间? 3个答案
Hi I have a problem : from server I get a time and it looks like this :
嗨,我有一个问题:从服务器我得到一个时间,它看起来像这样:
"date":"2017-05-24T07:56:22Z"
But now in my local time is 09:56:22 how I can convert this ?
但现在在我当地的时间是09:56:22我怎么能转换这个?
1 个解决方案
#1
2
First you need to parse the date, for example:
首先,您需要解析日期,例如:
Instant instant = Instant.parse("2017-05-24T07:56:22Z");
Assuming your time zone is correctly set, you can then simply use:
假设您的时区设置正确,您可以简单地使用:
LocalTime localTime = instant.atZone(ZoneId.systemDefault()).toLocalTime();
If you want to use a specific time zone instead of the system default time zone:
如果要使用特定时区而不是系统默认时区:
LocalTime localTime = instant.atZone(ZoneId.of("Europe/London")).toLocalTime();
#1
2
First you need to parse the date, for example:
首先,您需要解析日期,例如:
Instant instant = Instant.parse("2017-05-24T07:56:22Z");
Assuming your time zone is correctly set, you can then simply use:
假设您的时区设置正确,您可以简单地使用:
LocalTime localTime = instant.atZone(ZoneId.systemDefault()).toLocalTime();
If you want to use a specific time zone instead of the system default time zone:
如果要使用特定时区而不是系统默认时区:
LocalTime localTime = instant.atZone(ZoneId.of("Europe/London")).toLocalTime();