Java,DateTimeFormatter 未考虑 ZoneDateTime 的时区

Java, DateTimeFormatter is not considering ZoneDateTime's timezone

我有这行代码:

// I pass milliseconds timestamp on time var
ZonedDateTime zonedDatetIme = ZonedDateTime.ofInstant(java.time.Instant.ofEpochMilli(time), java.time.ZoneId.of("Asia/Almaty"))

这次我尝试输出时,它returns这个:

System.our.println(zonedDatetIme)
// returns
2020-01-24T17:00+06:00[Asia/Almaty]

然后我尝试格式化这个日期时间:

DateTimeFormatter formatter = DateTimeFormatter.ofPattern('dd.MM.yyyy hh:mm');
System.our.println(formatter.format(zonedDateTime));

哪个 returns 对我来说:

24.01.2020 05:00

这是错误的。这就像减去我的时区的 6 小时而不是添加它。为什么会这样?

您可能混淆了 hH - h 是 AM/PM 意义上的时钟小时(在您的示例中:05:00 PM = 17:00) 而 H 是一天中的小时。