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.temporal.*;
  9. import java.time.format.*;
  10.  
  11. /* Name of the class has to be "Main" only if the class is public. */
  12. class Ideone
  13. {
  14. public static void main (String[] args) throws java.lang.Exception
  15. {
  16.  
  17. ZoneId zP_K = ZoneId.of( "Pacific/Kiritimati" ) ;
  18. ZoneId zP_G = ZoneId.of( "Pacific/Gambier" ) ;
  19.  
  20. Instant instant = Instant.now() ; // Current moment in UTC, with resolution up to nanoseconds.
  21.  
  22. ZonedDateTime zdtP_K = instant.atZone( zP_K ) ;
  23. ZonedDateTime zdtP_G = instant.atZone( zP_G ) ;
  24.  
  25. Boolean sameMoment = zdtP_K.isEqual( zdtP_G ) ;
  26.  
  27. System.out.println( "instant.toString(): " + instant ) ;
  28. System.out.println( "zdtP_K.toString(): " + zdtP_K ) ;
  29. System.out.println( "zdtP_G.toString(): " + zdtP_G ) ;
  30. System.out.println( "sameMoment: " + sameMoment ) ;
  31.  
  32. }
  33. }
Success #stdin #stdout 0.15s 4386816KB
stdin
Standard input is empty
stdout
instant.toString(): 2017-06-15T12:53:35.276Z
zdtP_K.toString(): 2017-06-16T02:53:35.276+14:00[Pacific/Kiritimati]
zdtP_G.toString(): 2017-06-15T03:53:35.276-09:00[Pacific/Gambier]
sameMoment: true