要将a转换
LocalDateTime为另一个时区,请首先使用
atZone(),将其返回a
ZonedDateTime,然后再将其转换为新时区
withZoneSameInstant(),最后将结果转换回a
LocalDateTime。
LocalDateTime oldDateTime = LocalDateTime.parse("2015-10-10T10:00:00");ZoneId oldZone = ZoneId.of("America/Chicago");ZoneId newZone = ZoneId.of("America/New_York");LocalDateTime newDateTime = oldDateTime.atZone(oldZone) .withZoneSameInstant(newZone) .toLocalDateTime();System.out.println(newDateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));2015-10-10T11:00:00如果跳过最后一步,则保留该区域。
ZonedDateTime newDateTime = oldDateTime.atZone(oldZone) .withZoneSameInstant(newZone);System.out.println(newDateTime.format(DateTimeFormatter.ISO_DATE_TIME));2015-10-10T11:00:00-04:00[America/New_York]



