时区列表
public static String getTimeByZoneID(String zoneID) {
String formatted = null;
if (ZoneId.getAvailableZoneIds().contains(zoneID)) {
ZoneId zoneId = ZoneId.of(zoneID);
ZonedDateTime now = ZonedDateTime.now(zoneId);
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss 'UTC'xxx");
formatted = now.format(dateTimeFormatter);
} else {
System.out.println("zoneID有误!");
}
return formatted;
}
public static void main(String[] args) {
String timeZoneByID = getTimeByZoneID("America/New_York"); // Asia/Shanghai
System.out.println(timeZoneByID);
}