Guest User

Untitled

a guest
Feb 22nd, 2018
734
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. import java.time.LocalDateTime;
  2. import java.time.ZoneId;
  3. import java.util.AbstractMap.SimpleEntry;
  4. import java.util.Map;
  5.  
  6. public class DisplayZoneAndOffSet {
  7.  
  8.   public static final boolean SORT_BY_REGION = false;
  9.  
  10.   public static void main(String[] args) {
  11.  
  12.     LocalDateTime localDateTime = LocalDateTime.now();
  13.  
  14.     long total = ZoneId.getAvailableZoneIds()
  15.         .stream()
  16.         .map(ZoneId::of)
  17.         .map(zoneId -> new SimpleEntry<>(zoneId.toString(), localDateTime.atZone(zoneId)
  18.             .getOffset()
  19.             .getId()
  20.             .replaceAll("Z", "+00:00")))
  21.         .sorted(SORT_BY_REGION
  22.             ? Map.Entry.comparingByKey()
  23.             : Map.Entry.<String, String>comparingByValue().reversed())
  24.         .peek(e -> System.out.printf(String.format("%35s (UTC%s) %n", e.getKey(), e.getValue())))
  25.         .count();
  26.  
  27.     System.out.println("\nTotal Zone IDs " + total);
  28.   }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment