private TimeZones() { HashSet<String> availableIdsSet = new HashSet<>(Arrays.asList(TimeZone.getAvailableIDs())); for (TimeZoneMapping zoneMapping : ZONEMAPPINGS) { String id = zoneMapping.getOlsonName(); if (!availableIdsSet.contains(id)) { throw new IllegalStateException("Unknown ID [" + id + "]"); } TimeZone timeZone = TimeZone.getTimeZone(id); timeZones.add(new TimeZoneWithDisplayNames(timeZone, zoneMapping.getWindowsDisplayName(), zoneMapping.getWindowsStandardName())); } Collections.sort(timeZones, (a, b) -> { int diff = a.getTimeZone().getRawOffset() - b.getTimeZone().getRawOffset(); if (diff < 0) { return -1; } else if (diff > 0) { return 1; } else { return a.getDisplayName().compareTo(b.getDisplayName()); } }); }
private TimeZones() { HashSet<String> availableIdsSet = new HashSet<>(Arrays.asList(TimeZone.getAvailableIDs())); for (TimeZoneMapping zoneMapping : ZONEMAPPINGS) { String id = zoneMapping.getOlsonName(); if (!availableIdsSet.contains(id)) { throw new IllegalStateException("Unknown ID [" + id + "]"); } TimeZone timeZone = TimeZone.getTimeZone(id); timeZones.add(new TimeZoneWithDisplayNames(timeZone, zoneMapping.getWindowsDisplayName(), zoneMapping.getWindowsStandardName())); } Collections.sort(timeZones, (a, b) -> { int diff = a.getTimeZone().getRawOffset() - b.getTimeZone().getRawOffset(); if (diff < 0) { return -1; } else if (diff > 0) { return 1; } else { return a.getDisplayName().compareTo(b.getDisplayName()); } }); }
public static void main(String[] args) { List<TimeZoneWithDisplayNames> returnedZones = TimeZones.getInstance().getTimeZones(); for (TimeZoneWithDisplayNames zone : returnedZones) { System.out.println(zone.getDisplayName()); } }
public static void main(String[] args) { List<TimeZoneWithDisplayNames> returnedZones = TimeZones.getInstance().getTimeZones(); for (TimeZoneWithDisplayNames zone : returnedZones) { System.out.println(zone.getDisplayName()); } }