Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java ZoneDateTime.WithZoneMaiInstant和ZoneDateTime.WithZoneMalLocal之间有什么区别?_Java_Java Time - Fatal编程技术网

Java ZoneDateTime.WithZoneMaiInstant和ZoneDateTime.WithZoneMalLocal之间有什么区别?

Java ZoneDateTime.WithZoneMaiInstant和ZoneDateTime.WithZoneMalLocal之间有什么区别?,java,java-time,Java,Java Time,假设我有一个分区的约会时间: ZonedDateTime zonedDateTime = ZonedDateTime.of(LocalDateTime.now(), ZoneId.of("US/Pacific")); 我想知道现在是哪一天/时间,比如说在柏林。 我有两种方法: zonedDateTime.withZoneSameInstant(ZoneId.of("Europe/Berlin")); // probably this is the right one to get

假设我有一个分区的约会时间:

ZonedDateTime zonedDateTime = 
     ZonedDateTime.of(LocalDateTime.now(), ZoneId.of("US/Pacific"));
我想知道现在是哪一天/时间,比如说在柏林。 我有两种方法:

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"));
with zones melocal
方法的文档说:“仅当本地日期时间对新区域无效时才会更改…”并且不清楚何时会发生这种情况(任何示例?=)


它们各自代表的日期/时间以及区别是什么?

如果要将时间戳从一个时区转换为另一个时区,请使用
with zonesamainstant()
WithZones melocal()
将更改区域,但所有其他字段保持不变。例外情况是该时区中的日期无效

比如说,

ZonedDateTime dtUTC = ZonedDateTime.parse("2019-03-10T02:30:00Z");
ZoneId pacific = ZoneId.of("US/Pacific");
System.out.println(dtUTC.withZoneSameInstant(pacific));
System.out.println(dtUTC.withZoneSameLocal(pacific));


第一行是转换为另一时区的原始时间戳。第二个选项试图保留日期/时间字段,但2:30不是该日期的有效时间(因为夏令时跳转),因此它将其移动一小时。

那么这是否意味着WithZoneSaimInstant不处理WithZoneSaimInstant负责的夏令时@Shmoselt他们都知道DST。
2019-03-09T18:30-08:00[US/Pacific]
2019-03-10T03:30-07:00[US/Pacific]