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.  
  8. import java.time.*;
  9. import java.time.temporal.*;
  10. import java.time.format.*;
  11.  
  12. /* Name of the class has to be "Main" only if the class is public. */
  13. class Ideone
  14. {
  15. public static void main (String[] args) throws java.lang.Exception
  16. {
  17.  
  18. String input = "2018-02-13T10:20:12.120+0000".replace( "+0000" , "+00:00" );
  19. OffsetDateTime odt = OffsetDateTime.parse( input );
  20.  
  21. Instant instant = odt.toInstant();
  22.  
  23. ZoneId z = ZoneId.of( "America/Montreal" );
  24. ZonedDateTime zdt = odt.atZoneSameInstant( z );
  25.  
  26. System.out.println( "odt.toString(): " + odt );
  27. System.out.println( "instant.toString(): " + instant );
  28. System.out.println( "zdt.toString(): " + zdt );
  29.  
  30. }
  31. }
Success #stdin #stdout 0.18s 4386816KB
stdin
Standard input is empty
stdout
odt.toString(): 2018-02-13T10:20:12.120Z
instant.toString(): 2018-02-13T10:20:12.120Z
zdt.toString(): 2018-02-13T05:20:12.120-05:00[America/Montreal]