package com.mkyong.date; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.util.*; public class DisplayZoneAndOffSet { public static void main(String[] argv) { Map<String, String> sortedMap = new LinkedHashMap<>(); List<String> zoneList = new ArrayList<>(ZoneId.getAvailableZoneIds()); //Get all ZoneIds Map<String, String> allZoneIds = getAllZoneIds(zoneList); //sort map by key /*allZoneIds.entrySet().stream() .sorted(Map.Entry.comparingByKey()) .forEachOrdered(e -> sortedMap.put(e.getKey(), e.getValue()));*/ //sort by value, descending order allZoneIds.entrySet().stream() .sorted(Map.Entry.<String, String>comparingByValue().reversed()) .forEachOrdered(e -> sortedMap.put(e.getKey(), e.getValue())); // print map sortedMap.forEach((k, v) -> { String out = String.format("%35s (UTC%s) %n", k, v); System.out.printf(out); }); System.out.println("\nTotal Zone IDs " + sortedMap.size()); } private static Map<String, String> getAllZoneIds(List<String> zoneList) { Map<String, String> result = new HashMap<>(); LocalDateTime dt = LocalDateTime.now(); for (String zoneId : zoneList) { ZoneId zone = ZoneId.of(zoneId); ZonedDateTime zdt = dt.atZone(zone); ZoneOffset zos = zdt.getOffset(); //replace Z to +00:00 String offset = zos.getId().replaceAll("Z", "+00:00"); result.put(zone.toString(), offset); } return result; } }
Output
//display all zone id and its UTC offset
Etc/GMT+12 (UTC-12:00)
Pacific/Pago_Pago (UTC-11:00) Pacific/Samoa (UTC-11:00) Pacific/Niue (UTC-11:00) US/Samoa (UTC-11:00) Etc/GMT+11 (UTC-11:00) Pacific/Midway (UTC-11:00) Pacific/Honolulu (UTC-10:00) Pacific/Rarotonga (UTC-10:00) Pacific/Tahiti (UTC-10:00) Pacific/Johnston (UTC-10:00) US/Hawaii (UTC-10:00) SystemV/HST10 (UTC-10:00) Etc/GMT+10 (UTC-10:00) Pacific/Marquesas (UTC-09:30) Etc/GMT+9 (UTC-09:00) Pacific/Gambier (UTC-09:00) America/Atka (UTC-09:00) SystemV/YST9 (UTC-09:00) America/Adak (UTC-09:00) US/Aleutian (UTC-09:00) Etc/GMT+8 (UTC-08:00) US/Alaska (UTC-08:00) America/Juneau (UTC-08:00) America/Metlakatla (UTC-08:00) America/Yakutat (UTC-08:00) Pacific/Pitcairn (UTC-08:00) America/Sitka (UTC-08:00) America/Anchorage (UTC-08:00) SystemV/PST8 (UTC-08:00) America/Nome (UTC-08:00) SystemV/YST9YDT (UTC-08:00) Canada/Yukon (UTC-07:00) US/Pacific-New (UTC-07:00) Etc/GMT+7 (UTC-07:00) US/Arizona (UTC-07:00) America/Dawson_Creek (UTC-07:00) Canada/Pacific (UTC-07:00) PST8PDT (UTC-07:00) SystemV/MST7 (UTC-07:00) America/Dawson (UTC-07:00) Mexico/BajaNorte (UTC-07:00) America/Tijuana (UTC-07:00) America/Creston (UTC-07:00) America/Hermosillo (UTC-07:00) America/Santa_Isabel (UTC-07:00) America/Vancouver (UTC-07:00) America/Ensenada (UTC-07:00) America/Phoenix (UTC-07:00) America/Whitehorse (UTC-07:00) America/Fort_Nelson (UTC-07:00) SystemV/PST8PDT (UTC-07:00) America/Los_Angeles (UTC-07:00) US/Pacific (UTC-07:00) America/El_Salvador (UTC-06:00) America/Guatemala (UTC-06:00) America/Belize (UTC-06:00) America/Managua (UTC-06:00) America/Tegucigalpa (UTC-06:00) Etc/GMT+6 (UTC-06:00) Mexico/BajaSur (UTC-06:00) America/Regina (UTC-06:00) America/Denver (UTC-06:00) Pacific/Galapagos (UTC-06:00) America/Yellowknife (UTC-06:00) America/Swift_Current (UTC-06:00) America/Inuvik (UTC-06:00) America/Mazatlan (UTC-06:00) America/Boise (UTC-06:00) America/Costa_Rica (UTC-06:00) Canada/East-Saskatchewan (UTC-06:00) MST7MDT (UTC-06:00) SystemV/CST6 (UTC-06:00) America/Chihuahua (UTC-06:00) America/Ojinaga (UTC-06:00) US/Mountain (UTC-06:00) America/Edmonton (UTC-06:00) Canada/Mountain (UTC-06:00) America/Cambridge_Bay (UTC-06:00) Navajo (UTC-06:00) SystemV/MST7MDT (UTC-06:00) Canada/Saskatchewan (UTC-06:00) America/Shiprock (UTC-06:00) America/Panama (UTC-05:00) America/Chicago (UTC-05:00) America/Eirunepe (UTC-05:00) Etc/GMT+5 (UTC-05:00) Pacific/Easter (UTC-05:00) Mexico/General (UTC-05:00) America/Porto_Acre (UTC-05:00) America/Guayaquil (UTC-05:00) America/Rankin_Inlet (UTC-05:00) US/Central (UTC-05:00) America/Rainy_River (UTC-05:00) America/Indiana/Knox (UTC-05:00) America/North_Dakota/Beulah (UTC-05:00) America/Monterrey (UTC-05:00) America/Jamaica (UTC-05:00) America/Atikokan (UTC-05:00) America/Coral_Harbour (UTC-05:00) America/North_Dakota/Center (UTC-05:00) America/Indiana/Tell_City (UTC-05:00) Chile/EasterIsland (UTC-05:00) America/Mexico_City (UTC-05:00) America/Matamoros (UTC-05:00) CST6CDT (UTC-05:00) America/Knox_IN (UTC-05:00) America/Bogota (UTC-05:00) America/Menominee (UTC-05:00) America/Resolute (UTC-05:00) SystemV/EST5 (UTC-05:00) Canada/Central (UTC-05:00) Brazil/Acre (UTC-05:00) America/Cancun (UTC-05:00) America/Lima (UTC-05:00) America/Bahia_Banderas (UTC-05:00) US/Indiana-Starke (UTC-05:00) America/Rio_Branco (UTC-05:00) SystemV/CST6CDT (UTC-05:00) Jamaica (UTC-05:00) America/Merida (UTC-05:00) America/North_Dakota/New_Salem (UTC-05:00