简体   繁体   English

java 8 LocalTime 到 LocalTime UTC

[英]java 8 LocalTime to LocalTime UTC

I have a LocalTime instance created by parsing as below我有一个通过如下解析创建的 LocalTime 实例

Below time("01:00:00") is in ET,以下时间(“01:00:00”)在东部时间,

LocalTime time1 = LocalTime.parse("01:00:00");

Now I want to convert this time1 to UTC LocalTime, NOT LocalDateTime or LocalDate.现在我想将这个 time1 转换为 UTC LocalTime,而不是 LocalDateTime 或 LocalDate。 How to use that?怎么用?

Now I want to convert this time1 to UTC LocalTime现在我想将这个 time1 转换为 UTC LocalTime

LocalTime fundamentally means 'timezone-less', and UTC is a timezone. LocalTime 基本上意味着“无时区”,而 UTC 是一个时区。

That is like saying: "I want to convert this shape into a circle.. but with corners'. If you stick a corner in a circle it is no longer a circle. If you want some LocalTime, 'but in UTC', it is no longer a LocalTime.这就像说:“我想把这个形状转换成一个圆......但是有角”。如果你把一个角粘在一个圆上,它就不再是一个圆了。如果你想要一些 LocalTime,'但在 UTC',它不再是 LocalTime。

OffsetTime ot = LocalTime.parse("01:00:00").atOffset(ZoneOffset.UTC);

will get you there.会带你到那里。 From there you can eg invoke .atDate(someLocalDate) to get an OffsetDateTime object out.例如,您可以从那里调用.atDate(someLocalDate)以获取OffsetDateTime object。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM