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. /* 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 = "Tue, 28 Apr 2015 06:17:40 GMT" ;
  18. DateTimeFormatter f = DateTimeFormatter.RFC_1123_DATE_TIME ;
  19. ZonedDateTime zdt = ZonedDateTime.parse( input , f ) ;
  20.  
  21. System.out.println( "zdt.toString(): " + zdt ) ;
  22.  
  23. System.out.println(
  24. ZonedDateTime
  25. .parse(
  26. "Tue, 28 Apr 2015 06:17:40 GMT" ,
  27. DateTimeFormatter.RFC_1123_DATE_TIME
  28. )
  29. .withZoneSameInstant(
  30. ZoneId.of( "America/Anchorage" )
  31. )
  32. .toString()
  33. );
  34.  
  35. }
  36. }
Success #stdin #stdout 0.14s 38700KB
stdin
Standard input is empty
stdout
zdt.toString(): 2015-04-28T06:17:40Z
2015-04-27T22:17:40-08:00[America/Anchorage]