fork(3) 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.  
  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.  
  15. OffsetDateTime odt = OffsetDateTime.now ( ZoneId.systemDefault () );
  16. ZoneOffset zoneOffsetOfOdt = odt.getOffset ();
  17.  
  18. System.out.println( "ZoneId.systemDefault().toString(): " + ZoneId.systemDefault ().toString() );
  19. System.out.println( "odt: " + odt );
  20. System.out.println( "zoneOffsetOfOdt: " + zoneOffsetOfOdt );
  21. System.out.println( "-------------------- " );
  22.  
  23. ZoneId z = ZoneId.of( "America/Montreal" );
  24. LocalDate ld = LocalDate.of( 2017 , 12 , 25 );
  25. ZonedDateTime zdtXmas = ld.atStartOfDay( z );
  26. ZoneOffset zoneOffsetXmas = zdtXmas.getOffset();
  27.  
  28. System.out.println( "zdtXmas.toString(): " + zdtXmas );
  29. System.out.println( "zoneOffsetXmas.toString(): " + zoneOffsetXmas );
  30. System.out.println( "zoneOffsetXmas.getTotalSeconds(): " + zoneOffsetXmas.getTotalSeconds() );
  31. System.out.println( "-------------------- " );
  32.  
  33. Instant instant = zdtXmas.toInstant();
  34. ZoneOffset zo = z.getRules().getOffset( instant );
  35.  
  36. System.out.println( "For ZoneId: " + z + " at instant: " + instant + " the ZoneOffset is: " + zo );
  37.  
  38. }
  39. }
Success #stdin #stdout 0.12s 711680KB
stdin
Standard input is empty
stdout
ZoneId.systemDefault().toString(): GMT
odt: 2017-01-03T00:08:42.627Z
zoneOffsetOfOdt: Z
-------------------- 
zdtXmas.toString(): 2017-12-25T00:00-05:00[America/Montreal]
zoneOffsetXmas.toString(): -05:00
zoneOffsetXmas.getTotalSeconds(): -18000
-------------------- 
For ZoneId: America/Montreal at instant: 2017-12-25T05:00:00Z the ZoneOffset is: -05:00