fork download
  1. import java.text.DateFormat;
  2. import java.text.ParseException;
  3. import java.text.SimpleDateFormat;
  4. import java.util.Calendar;
  5. import java.util.Date;
  6. import java.util.Locale;
  7.  
  8. /* The class name doesn't have to be Main, as long as the class is not public. */
  9. class Main
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
  14. SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyyMMdd HH:mm:ss '(Z)'");
  15. Date date1 = simpleDateFormat.parse(" 2012-08-12T14:18:39.000Z ");
  16. String formattedDate = simpleDateFormat1.format(date1); // 20120821
  17. // Date parsedDate = simpleDateFormat1.parse(formattedDate);
  18. System.out.println(formattedDate);
  19. }
  20. }
Success #stdin #stdout 0.15s 59128KB
stdin
Standard input is empty
stdout
20120812 14:18:39 (Z)