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.time.zone.* ;
  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. LocalDateTime ldt = LocalDateTime.parse( "2021-09-16T12:00" ) ;
  16. ZonedDateTime zdtAbidjan = ldt.atZone( ZoneId.of( "Africa/Abidjan" ) ) ;
  17. ZonedDateTime zdtLondon = zdtAbidjan.withZoneSameInstant( ZoneId.of( "Europe/London" ) ) ;
  18. Instant instant = zdtAbidjan.toInstant() ; // Adjust to UTC by extracting an `Instant` object.
  19.  
  20. System.out.println( "ldt: " + ldt ) ;
  21. System.out.println( "zdtAbidjan: " + zdtAbidjan ) ;
  22. System.out.println( "zdtLondon: " + zdtLondon ) ;
  23. System.out.println( "instant: " + instant ) ;
  24.  
  25. ZoneId z = ZoneId.of( "Africa/Abidjan" ) ;
  26. ZoneRules rules = z.getRules() ;
  27. ZoneOffset offset = rules.getOffset( LocalDateTime.parse( "2021-09-16T12:00" ) ) ;
  28. int offsetInSeconds = offset.getTotalSeconds() ;
  29.  
  30. System.out.println( "rules: " + rules ) ;
  31. System.out.println( "offset: " + offset ) ;
  32. System.out.println( "offsetInSeconds: " + offsetInSeconds ) ;
  33. }
  34. }
Success #stdin #stdout 0.2s 54292KB
stdin
Standard input is empty
stdout
ldt: 2021-09-16T12:00
zdtAbidjan: 2021-09-16T12:00Z[Africa/Abidjan]
zdtLondon: 2021-09-16T13:00+01:00[Europe/London]
instant: 2021-09-16T12:00:00Z
rules: ZoneRules[currentStandardOffset=Z]
offset: Z
offsetInSeconds: 0