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.  
  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. // Parse input string
  19. String input = "20110913T100702.631 GMT";
  20. DateTimeFormatter fInput = DateTimeFormatter.ofPattern ( "uuuuMMdd'T'HHmmss.SSS z" );
  21. ZonedDateTime zdt = ZonedDateTime.parse ( input, fInput );
  22.  
  23. // Generate output string
  24. Locale locale = Locale.US; // Or Locale.CANADA_FRENCH, Locale.ITALY, etc.
  25. DateTimeFormatter fOutput =
  26. DateTimeFormatter.ofLocalizedDateTime ( FormatStyle.FULL, FormatStyle.SHORT ) // Specify format style of date portion, then time-of-day portion.
  27. .withLocale ( locale );
  28. String output = zdt.format ( fOutput );
  29.  
  30. // Dump to console
  31. System.out.println ( "input: " + input );
  32. System.out.println ( "zdt.toString(): " + zdt );
  33. System.out.println ( "output: " + output );
  34.  
  35.  
  36. }
  37. }
Success #stdin #stdout 0.17s 4386816KB
stdin
Standard input is empty
stdout
input: 20110913T100702.631 GMT
zdt.toString(): 2011-09-13T10:07:02.631Z[GMT]
output: Tuesday, September 13, 2011 10:07 AM