fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.Date;
  7. import java.text.DateFormat;
  8. import java.text.ParseException;
  9. import java.text.SimpleDateFormat;
  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. String dateStr = "Thu Apr 02 09:49:16 CEST 2015";
  17. DateFormat readFormat = new SimpleDateFormat( "EEE MMM dd HH:mm:ss z yyyy");
  18.  
  19. DateFormat writeFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");
  20. Date date = null;
  21. try {
  22. date = readFormat.parse( dateStr );
  23. } catch ( ParseException e ) {
  24. e.printStackTrace();
  25. }
  26.  
  27. String formattedDate = "";
  28. if( date != null ) {
  29. formattedDate = writeFormat.format( date );
  30. }
  31.  
  32. System.out.println(formattedDate);
  33. }
  34. }
Success #stdin #stdout 0.16s 321152KB
stdin
Standard input is empty
stdout
2015-04-02 07:49:16