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.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. OffsetDateTime odt = OffsetDateTime.parse(
  17. "2018-12-04T22:22:01+1000" ,
  18. DateTimeFormatter.ofPattern( "uuuu-MM-dd'T'HH:mm:ssX" )
  19. )
  20. ;
  21.  
  22. System.out.println( "odt.toString(): " + odt ) ;
  23.  
  24. Instant instant = odt.toInstant() ;
  25.  
  26. System.out.println( "instant.toString(): " + instant ) ;
  27.  
  28. ZoneId z = ZoneId.of( "Europe/Paris" ) ;
  29. ZonedDateTime zdt = instant.atZone( z ) ;
  30.  
  31. System.out.println( "zdt.toString(): " + zdt ) ;
  32.  
  33. System.out.println(
  34.  
  35. OffsetDateTime.parse(
  36. "2018-12-04T22:22:01+1000" ,
  37. DateTimeFormatter.ofPattern( "uuuu-MM-dd'T'HH:mm:ssX" )
  38. )
  39. .toInstant() // Adjust into UTC.
  40. .atZone(
  41. ZoneId.of( "Europe/Brussels" )
  42. )
  43. .toString()
  44.  
  45. );
  46. }
  47. }
Success #stdin #stdout 0.17s 2184192KB
stdin
Standard input is empty
stdout
odt.toString(): 2018-12-04T22:22:01+10:00
instant.toString(): 2018-12-04T12:22:01Z
zdt.toString(): 2018-12-04T13:22:01+01:00[Europe/Paris]
2018-12-04T13:22:01+01:00[Europe/Brussels]