fork(1) 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. /* Name of the class has to be "Main" only if the class is public. */
  14. class Ideone
  15. {
  16. public static void main (String[] args) throws java.lang.Exception
  17. {
  18. // Specify the moment of launch as seen in Rome.
  19. LocalDate launchDateAsSeenInRome = LocalDate.of( 2021 , 1 , 23 ) ;
  20. LocalTime launchTimeAsSeenInRome = LocalTime.of( 21 , 0 ) ;
  21. ZoneId zoneEuropeRome = ZoneId.of( "Europe/Rome" ) ;
  22. ZonedDateTime launchMomentAsSeenInRome = ZonedDateTime.of( launchDateAsSeenInRome , launchTimeAsSeenInRome , zoneEuropeRome ) ;
  23.  
  24. System.out.println( "launchMomentAsSeenInRome.toString(): " + launchMomentAsSeenInRome ) ;
  25.  
  26. // Adjust from Rome time zone to UTC.
  27. Instant launchInstant = launchMomentAsSeenInRome.toInstant() ;
  28.  
  29. System.out.println( "launchInstant.toString(): " + launchInstant ) ;
  30.  
  31. // Convert to `OffsetDateTime` object for use with standard JDBC 4.2.
  32. OffsetDateTime odtLaunchAsSeenInRome = launchMomentAsSeenInRome.toOffsetDateTime() ;
  33.  
  34. // Adjust to some other time zone.
  35. ZoneId zoneAmericaNewYork = ZoneId.of( "America/New_York" ) ;
  36. ZonedDateTime launchAsSeenInNewYork = odtLaunchAsSeenInRome.atZoneSameInstant( zoneAmericaNewYork ) ;
  37.  
  38. System.out.println( "launchAsSeenInNewYork.toString(): " + launchAsSeenInNewYork ) ;
  39.  
  40.  
  41. }
  42. }
Success #stdin #stdout 0.15s 38740KB
stdin
Standard input is empty
stdout
launchMomentAsSeenInRome.toString(): 2021-01-23T21:00+01:00[Europe/Rome]
launchInstant.toString(): 2021-01-23T20:00:00Z
launchAsSeenInNewYork.toString(): 2021-01-23T15:00-05:00[America/New_York]