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. String input = "2017-04-21T17:46:00Z" ;
  18. Instant instant = Instant.parse( input ) ;
  19.  
  20. OffsetDateTime odt = instant.atOffset( ZoneOffset.UTC ) ;
  21.  
  22. DateTimeFormatter f = DateTimeFormatter.ofPattern( "hh:mm dd MMM yyyy" , Locale.US ) ;
  23. String output = odt.format( f ) ;
  24.  
  25. ZoneId z = ZoneId.of( "Europe/London" ) ;
  26. ZonedDateTime zdt = instant.atZone( z ) ;
  27.  
  28. System.out.println( "instant.toString(): " + instant ) ;
  29. System.out.println( "odt.toString(): " + odt ) ;
  30. System.out.println( "output: " + output ) ;
  31. System.out.println( "zdt.toString(): " + zdt ) ;
  32.  
  33. }
  34. }
Success #stdin #stdout 0.17s 4386816KB
stdin
Standard input is empty
stdout
instant.toString(): 2017-04-21T17:46:00Z
odt.toString(): 2017-04-21T17:46Z
output: 05:46 21 Apr 2017
zdt.toString(): 2017-04-21T18:46+01:00[Europe/London]