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. // Logic.
  17. final Locale locale = Locale.UK ; // Locale.UK versus Locale.US yield different outputs.
  18. final String input = "16/07/2017 19:28:33 EST";
  19. final DateTimeFormatter formatter = DateTimeFormatter.ofPattern( "dd/MM/yyyy HH:mm:ss z" ).withLocale( locale ) ;
  20. final ZonedDateTime zdt = ZonedDateTime.parse( input , formatter ) ;
  21. final String zdtToString = zdt.toString() ;
  22. final String zdtFormatted = zdt.format( formatter ) ;
  23.  
  24. // Dump to console.
  25. System.out.println( "input: " + input ) ;
  26. System.out.println( "zdt: " + zdt ) ;
  27. System.out.println( "zdtToString: " + zdtToString ) ;
  28. System.out.println( "zdtFormatted: " + zdtFormatted ) ;
  29.  
  30. }
  31. }
Success #stdin #stdout 0.48s 50192KB
stdin
Standard input is empty
stdout
input: 16/07/2017 19:28:33 EST
zdt: 2017-07-16T19:28:33-04:00[America/New_York]
zdtToString: 2017-07-16T19:28:33-04:00[America/New_York]
zdtFormatted: 16/07/2017 19:28:33 GMT-04:00