locadate。现在允许使用区域ID。
如果其日期使用Zone id day date date date.toinstant()。 (“”)。
.of ”> https://docs.oracle.com/javase/8/docs/api/java/java/java/date.html#toinstant--
noreferrer
Instant instant = Instant.parse("2022-06-18 00:00"); ZoneId zoneId = ZoneId.of("Asia/Tokyo"); LocalDateTime value LocalDateTime.ofInstant(instant, zoneId);
LocaDate.now allow with zone id. https://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html#now-java.time.ZoneId-
If its date use zone Id date.toInstant().atZone(ZoneId.of("")).toLocalDateTime()
https://docs.oracle.com/javase/8/docs/api/java/util/Date.html#toInstant--
Use Instant and zone id
是在DB中输入UTC中的时间。 时间:2022-06-17 15:00
我想将其转换为亚洲时间,以分区 localdateTime 。 (需要+09:00。)
localdateTime
我想要的时间:2022-06-18 00:00
但是,无论使用哪种方法,UTC标准中的时间都是输出的。
getmytime.atzone(...)。tolocaldateTime .. 输出:2022-06-17 15:00
getmytime.atzone(...)。tolocaldateTime ..
在寻找一种方式时,我发现LocalDateTime忽略(或删除)“区域”信息。
创建时间时,可以使用区域信息创建它,但是区域信息已经创建后没有含义。
,我越来越接近答案,然后找到了它。
ZonedDateTime.of(localDateTime,ZoneId.systemDefault()) .withZoneSameInstant(ZoneId.of("Asia/Seoul")) .toLocalDateTime();
获取基本时间的ZonEdateTime。
键
通过 with ZoneMameInstant 创建一个带有区域信息的即时,并将其创建为 localdateTime 。
with ZoneMameInstant
这对我来说非常有用。
The time in UTC is entered in the DB. time : 2022-06-17 15:00
I wanted to convert this to Asia time in a Zoned LocalDateTime. (+09:00 is required.)
LocalDateTime
The time I want: 2022-06-18 00:00
However, no matter which method was used, the time in UTC standard was output as it is.
getMyTime.atZone(...).toLocalDateTime .. Output: 2022-06-17 15:00
getMyTime.atZone(...).toLocalDateTime ..
While looking for a way, I found that LocalDateTime ignores (or deletes) the "zone" information.
When creating time, it can be created with zone information, but zone information has no meaning after it has already been created.
From then on, I got closer to the answer, and I found it.
Get the zoneDateTime of the base time.
and the key
Create an instant with zone information through withZoneSameInstant and create it as LocalDateTime.
withZoneSameInstant
This works perfectly for me.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
暂无简介
文章 0 评论 0
接受
发布评论
评论(2)
locadate。现在允许使用区域ID。
如果其日期使用Zone id day date date date.toinstant()。 (“”)。
.of ”> https://docs.oracle.com/javase/8/docs/api/java/java/java/date.html#toinstant--
noreferrer
LocaDate.now allow with zone id.
https://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html#now-java.time.ZoneId-
If its date use zone Id date.toInstant().atZone(ZoneId.of("")).toLocalDateTime()
https://docs.oracle.com/javase/8/docs/api/java/util/Date.html#toInstant--
Use Instant and zone id
意图和问题的原因
是在DB中输入UTC中的时间。
时间:2022-06-17 15:00
我想将其转换为亚洲时间,以分区
localdateTime
。(需要+09:00。)
我想要的时间:2022-06-18 00:00
但是,无论使用哪种方法,UTC标准中的时间都是输出的。
getmytime.atzone(...)。tolocaldateTime ..
输出:2022-06-17 15:00
在寻找一种方式时,我发现LocalDateTime忽略(或删除)“区域”信息。
创建时间时,可以使用区域信息创建它,但是区域信息已经创建后没有含义。
从那时起的解决方案
,我越来越接近答案,然后找到了它。
获取基本时间的ZonEdateTime。
键
通过
with ZoneMameInstant
创建一个带有区域信息的即时,并将其创建为localdateTime
。这对我来说非常有用。
Intent and cause of the question
The time in UTC is entered in the DB.
time : 2022-06-17 15:00
I wanted to convert this to Asia time in a Zoned
LocalDateTime
.(+09:00 is required.)
The time I want: 2022-06-18 00:00
However, no matter which method was used, the time in UTC standard was output as it is.
getMyTime.atZone(...).toLocalDateTime ..
Output: 2022-06-17 15:00
While looking for a way, I found that LocalDateTime ignores (or deletes) the "zone" information.
When creating time, it can be created with zone information, but zone information has no meaning after it has already been created.
The solution
From then on, I got closer to the answer, and I found it.
Get the zoneDateTime of the base time.
and the key
Create an instant with zone information through
withZoneSameInstant
and create it asLocalDateTime
.This works perfectly for me.