ZoneId
ZoneId zone = ZoneId.of("Asia/Shanghai");
ZoneId.systemDefault();
Set zones = ZoneId.getAvailableZoneIds();
ZonedDateTime
ZonedDateTime zdt = ZonedDateTime.now();
ZonedDateTime zdt2 = ZonedDateTime.of(2026, 6, 15, 10, 30, 0, 0, zone);
ZonedDateTime converted = zdt.withZoneSameInstant(ZoneId.of("America/New_York"));
Instant
Instant instant = Instant.now();
instant.atZone(zone);
long epochSecond = instant.getEpochSecond();
Instant fromEpoch = Instant.ofEpochSecond(epochSecond);
小结
- ZoneId表示时区ID
- ZonedDateTime带时区的日期时间
- Instant表示时间戳(UTC)
- withZoneSameInstant转换时区