There is data in the String "2018-07-09T08:26:38.125+0000" . I'm trying to get a day a month a year an hour a minute, I wrote a method:

 public static String convertToDateAndTime(String dateTimeZone) throws ParseException { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss:S'Z'"); Date newDate=formatter.parse(dateTimeZone); formatter=new SimpleDateFormat("dd-mm-yyyy hh:mm"); String date=formatter.format(newDate); return date; } 

Gives an error message:

W / System.err: java.text.ParseException: Unparseable date: "2018-07-09T08: 26: 38.125 + 0000"

    2 answers 2

    Correct the format to: yyyy-MM-dd'T'HH:mm:ss.SSSZ

      You have an invalid date format. The source line is in ISO 8601 format, for which the correct format is:

       String ISO_8601_FORMAT_STRING="yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; 

      Update:

      Z - Zulu time without quotes

       String ISO_8601_FORMAT_STRING="yyyy-MM-dd'T'HH:mm:ss.SSSZ"; 
      • vseravno falls - elik
      • one
        yyyy-MM-dd'T'HH:mm:ss.SSSZ - Z without quotes - Sergi
      • Yes, that's right - Z without quotes - Barmaley