相关疑难解决方法(0)

ZonedDateTime.withZoneSameInstant 和 ZonedDateTime.withZoneSameLocal 有什么区别?

假设我有一个 ZonedDateTime:

ZonedDateTime zonedDateTime = 
     ZonedDateTime.of(LocalDateTime.now(), ZoneId.of("US/Pacific"));
Run Code Online (Sandbox Code Playgroud)

我想知道它是在柏林的哪个日期/时间。我有两种方法:

zonedDateTime.withZoneSameInstant(ZoneId.of("Europe/Berlin")); // probably this is the right one to get the corresponding date/time in Berlin

zonedDateTime.withZoneSameLocal(ZoneId.of("Europe/Berlin"));
Run Code Online (Sandbox Code Playgroud)

该withZoneSameLocal方法的文档说:“仅当本地日期时间对新区域无效时才会更改......”并且不清楚何时真的会发生(任何示例?=))。

它们各自代表哪个日期/时间,有什么区别?

java java-time

12
推荐指数
1
解决办法
5487
查看次数

标签 统计

java ×1

java-time ×1