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. import java.time.temporal.* ;
  10.  
  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. // Generating RFC 1123 text
  19. Instant instant = Instant.parse( "2019-09-18T20:15:32.162Z" ) ;
  20. OffsetDateTime odt = instant.atOffset( ZoneOffset.UTC ) ;
  21. String output = odt.format( DateTimeFormatter.RFC_1123_DATE_TIME ) ;
  22.  
  23. System.out.println( "output: " + output ) ;
  24.  
  25. // Parsing RFC 1123 text
  26. OffsetDateTime odt2 = OffsetDateTime.parse( output , DateTimeFormatter.RFC_1123_DATE_TIME ) ;
  27.  
  28. System.out.println( "odt2.toString(): " + odt2 ) ;
  29. }
  30. }
Success #stdin #stdout 0.11s 37504KB
stdin
Standard input is empty
stdout
output: Wed, 18 Sep 2019 20:15:32 GMT
odt2.toString(): 2019-09-18T20:15:32Z