How do I parse the date string below into a Date object?
String target = "Thu Sep 28 20:29:30 JST 2000";
DateFormat df = new SimpleDateFormat("E MM dd kk:mm:ss z yyyy");
Date result = df.parse(target);
Throws exception…
java.text.ParseException: Unparseable date: "Thu Sep 28 20:29:30 JST 2000"
at java.text.DateFormat.parse(DateFormat.java:337)
The pattern is wrong. You have a 3-letter day abbreviation, so it must be
EEE. You have a 3-letter month abbreviation, so it must beMMM. As those day and month abbreviations are locale sensitive, you’d like to explicitly specify theSimpleDateFormatlocale to English as well, otherwise it will use the platform default locale which may not be English per se.This prints here
which is correct as per my timezone.
I would also reconsider if you wouldn’t rather like to use
HHinstead ofkk. Read the javadoc for details about valid patterns.