Looking at the source code of DateFormatPatterns, ISO8601
is defined as "yyyy-MM-dd'T'HH:mm:ssZ".
Putting that into a minimal plain old Java example:
import java.util.Date;
import java.text.*;
public class DateProblem {
public static void main(String[] args) throws Exception {
String input = "2019-08-30T00:34:34Z";
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
// DateFormatPatterns.ISO8601
Date date = format.parse(input);
System.out.println(date);
}
}
gets me an "unparsable date" error (but not the string index error you got).
Checking the Javadoc for SimpleDateFormat shows that Z
stands for RFC 822 format, that is a+
or -
and 4 digits (offset in hours and minutes from GMT). Change the Z
in your input to such a time zone offset, for example like this:
String input = "2019-08-30T00:34:34-0600";
This parses fine for me.
That said, the whole SimpleDateFormat
et al are deprecated. You should switch to the new java.time API