fork(2) 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.time.format.* ;
  9. import java.time.temporal.* ;
  10. import java.time.chrono.* ;
  11. import java.time.zone.* ;
  12.  
  13. import java.util.concurrent.TimeUnit ;
  14.  
  15.  
  16. /* Name of the class has to be "Main" only if the class is public. */
  17. class Ideone
  18. {
  19. public static void main (String[] args) throws java.lang.Exception
  20. {
  21. // Convert your milliseconds to an offset-from-UTC.
  22. int milliseconds = 21_600_000;
  23. int seconds = Math.toIntExact( TimeUnit.MILLISECONDS.toSeconds( milliseconds ) );
  24. ZoneOffset targetOffset = ZoneOffset.ofTotalSeconds( seconds );
  25.  
  26. // Capture the current moment as seen in UTC (an offset of zero hours-minutes-seconds).
  27. Instant now = Instant.now();
  28.  
  29. // Loop through all know time zones, comparing each one’s zone to the target zone.
  30. List < ZoneId > hits = new ArrayList <>();
  31. Set < String > zoneNames = ZoneId.getAvailableZoneIds();
  32. for ( String zoneName : zoneNames )
  33. {
  34. ZoneId zoneId = ZoneId.of( zoneName );
  35.  
  36. ZoneRules rules = zoneId.getRules();
  37. // ZoneRules rules = zoneId.getRules() ;
  38. ZoneOffset offset = rules.getOffset( now );
  39. if ( offset.equals( targetOffset ) )
  40. {
  41. hits.add( zoneId );
  42. }
  43. }
  44.  
  45. // Report results.
  46. System.out.println( "java.version " + System.getProperty("java.version") ) ;
  47. System.out.println( "java.vendor " + System.getProperty("java.vendor") ) ;
  48. System.out.println() ;
  49. System.out.println( "targetOffset = " + targetOffset );
  50. System.out.println( "hits: " + hits );
  51. }
  52. }
Success #stdin #stdout 0.76s 57684KB
stdin
Standard input is empty
stdout
java.version 12.0.1
java.vendor Oracle Corporation

targetOffset = +06:00
hits: [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]