fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.time.* ;
  7. import java.time.zone.*;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. final Instant now = Instant.now ( );
  15. final ZoneOffset offsetTarget = ZoneOffset.ofHours ( -4 ); // -04:00
  16.  
  17. final Set < String > zoneNames = ZoneId.getAvailableZoneIds ( );
  18. final Collection < ZoneId > zoneIdsWithTargetOffset = new ArrayList <> ( );
  19. for ( String zoneName : zoneNames )
  20. {
  21. ZoneId zoneId = ZoneId.of ( zoneName );
  22. ZoneRules rules = zoneId.getRules ( );
  23. ZoneOffset offset = rules.getOffset ( now );
  24. if ( offset.equals ( offsetTarget ) )
  25. {
  26. zoneIdsWithTargetOffset.add ( zoneId );
  27. }
  28. }
  29. System.out.println ( "At " + now + ", " + zoneIdsWithTargetOffset.size ( ) + " zones have an offset of " + offsetTarget + " ➡️ " + zoneIdsWithTargetOffset ); // ️
  30.  
  31. }
  32. }
Success #stdin #stdout 0.85s 79728KB
stdin
Standard input is empty
stdout
At 2023-11-21T22:01:25.036335Z, 41 zones have an offset of -04:00 ➡️ [America/Marigot, Canada/Atlantic, Etc/GMT+4, America/Manaus, America/St_Thomas, America/Anguilla, America/Barbados, America/Curacao, America/Guyana, America/Martinique, America/Puerto_Rico, America/Port_of_Spain, SystemV/AST4, America/Kralendijk, America/Antigua, America/Moncton, America/St_Vincent, America/Dominica, Atlantic/Bermuda, Brazil/West, America/Aruba, America/Halifax, America/La_Paz, America/Blanc-Sablon, America/Santo_Domingo, America/Glace_Bay, America/St_Barthelemy, America/St_Lucia, America/Montserrat, America/Lower_Princes, America/Thule, America/Tortola, America/Porto_Velho, America/Goose_Bay, America/Virgin, America/Boa_Vista, America/Grenada, America/St_Kitts, America/Caracas, America/Guadeloupe, SystemV/AST4ADT]