fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. import java.time.* ;
  8. import java.util.stream.Collectors ;
  9.  
  10. /* Name of the class has to be "Main" only if the class is public. */
  11. class Ideone
  12. {
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15.  
  16. Instant instant = Instant.now() ;
  17. ZoneOffset targetOffset = ZoneOffset.ofHours( 6 ) ;
  18. List< ZoneId > zonesUsingDesiredOffset =
  19. ZoneId
  20. .getAvailableZoneIds() // Returns a `Set` of `String` objects, the names of each known time zone.
  21. .stream()
  22. .map( zoneName -> ZoneId.of( zoneName ) ) // Map each zone name to `ZoneId` object.
  23. .filter(
  24. zoneId -> zoneId.getRules().getOffset( instant ).equals( targetOffset ) // Filter for zones whose offset at specified moment matches our desired offset.
  25. )
  26. .collect( Collectors.toList() )
  27. ;
  28.  
  29. System.out.println( zonesUsingDesiredOffset ) ;
  30.  
  31. }
  32. }
Success #stdin #stdout 0.59s 76252KB
stdin
Standard input is empty
stdout
[Asia/Kashgar, Etc/GMT-6, Asia/Almaty, Asia/Dacca, Asia/Omsk, Asia/Dhaka, Indian/Chagos, Asia/Qyzylorda, Asia/Bishkek, Antarctica/Vostok, Asia/Urumqi, Asia/Thimbu, Asia/Thimphu]