fork(8) 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.  
  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.  
  16. ZoneId zoneParis = ZoneId.of( "Europe/Paris" );
  17. ZoneId zoneMontreal = ZoneId.of( "America/Montreal" );
  18. ZoneId zoneAuckland = ZoneId.of( "Pacific/Auckland" );
  19.  
  20. OffsetDateTime odt = OffsetDateTime.parse( "2015-07-09T05:10:00+02:00" );
  21. Instant instant = odt.toInstant(); // `Instant` is always in UTC by definition.
  22.  
  23. ZonedDateTime zdtParis = odt.atZoneSameInstant( zoneParis );
  24. ZonedDateTime zdtMontreal = odt.atZoneSameInstant( zoneMontreal );
  25. ZonedDateTime zdtAuckland = zdtMontreal.withZoneSameInstant( zoneAuckland );
  26.  
  27. DateTimeFormatter f = DateTimeFormatter.ofLocalizedDateTime( FormatStyle.FULL ).withLocale( Locale.CANADA_FRENCH );
  28. String output = zdtMontreal.format( f );
  29.  
  30. System.out.println( "odt.toString(): " + odt );
  31. System.out.println( "instant.toString(): " + instant );
  32. System.out.println( "zdtParis.toString(): " + zdtParis );
  33. System.out.println( "zdtMontreal.toString(): " + zdtMontreal );
  34. System.out.println( "zdtAuckland.toString(): " + zdtAuckland );
  35. System.out.println( "output: " + output );
  36.  
  37. }
  38. }
Success #stdin #stdout 0.13s 712192KB
stdin
Standard input is empty
stdout
odt: 2015-07-09T05:10+02:00
instant: 2015-07-09T03:10:00Z
zdtParis: 2015-07-09T05:10+02:00[Europe/Paris]
zdtMontreal: 2015-07-08T23:10-04:00[America/Montreal]
zdtAuckland: 2015-07-09T15:10+12:00[Pacific/Auckland]
output: mercredi 8 juillet 2015 23 h 10 EDT