mongodb 本地日期时间到RealmInstant的转换

k10s72fa  于 2022-11-28  发布在  Go
关注(0)|答案(1)|浏览(96)

有人能建议一种将简单的LocalDateTime转换为RealmInstant的方法吗?
我已经尝试过这种方法,我的意思是这个转换后的LocalDate时间值的格式与RealmInstant的格式不同。
良好的RealmInstant值(与下面的日期/时间值不同,但格式是此处的关键):

+054848-03-16T07:54:02.000+00:00

从LocalDateTime到RealmInstant的转换错误:

2022-11-23T22:04:06.000+00:00

下面是我用来将LocalDateTime转换为RealmInstant的代码:

RealmInstant.from(
    epochSeconds = LocalDateTime.of(pickedDate, pickedTime).toEpochSecond(ZoneOffset.UTC),
    nanosecondAdjustment = LocalDateTime.of(pickedDate, pickedTime).nano
)
nx7onnlm

nx7onnlm1#

也许解析使它的格式不同?

LocalDateTime ldt = LocalDateTime.parse("2022-11-23T22:04:06")
RealmIstant ri = RealmInstant.from(ldt.toEpochSecond(ZoneOffset.UTC), ldt.nano)
Date date = LocalDateTime.ofEpochSecond(ri.epochSeconds, ri.nanosecondsOfSecond, ZoneOffset.UTC)

相关问题