fork(4) 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.text.DateFormat;
  7. import java.text.SimpleDateFormat;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. String date = "2018-09-14T13:05:21.3Z";
  15. DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
  16. SimpleDateFormat sdfDestination = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  17. try {
  18. Date parsedDate = formatter.parse(date);
  19. String destDate = sdfDestination.format(parsedDate);
  20. System.out.print(destDate);
  21. } catch (java.text.ParseException parseException) {
  22. System.out.println("Parse Exception occured while converting publication time to date "
  23. + "format 'yyyy-MM-dd HH:mm:ss'");
  24. }
  25. }
  26. }
Success #stdin #stdout 0.12s 2184192KB
stdin
Standard input is empty
stdout
2018-09-14 13:05:21