fork download
  1. import java.time.ZonedDateTime;
  2. import java.time.format.DateTimeFormatter;
  3. import java.util.Locale;
  4.  
  5. public class Main {
  6. public static void main(String[] args) {
  7. String strDateTime = "31 October 2011 11:19:56 GMT";
  8.  
  9. DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd MMMM uuuu HH:mm:ss z", Locale.ENGLISH);
  10.  
  11. ZonedDateTime zdt = ZonedDateTime.parse(strDateTime, dtf);
  12. System.out.println(zdt);
  13.  
  14. // Some other format
  15. DateTimeFormatter dtfAnother = DateTimeFormatter.ofPattern("MMMM dd HH:mm:ss z uuuu", Locale.ENGLISH);
  16. String strDate = dtfAnother.format(zdt);
  17. System.out.println(strDate);
  18. }
  19. }
Success #stdin #stdout 0.16s 55944KB
stdin
Standard input is empty
stdout
2011-10-31T11:19:56Z[GMT]
October 31 11:19:56 GMT 2011