I am using SimpleDateFormat and I am getting ParseException as shown below.
java.text.ParseException: Unparseable date: "Mon Jul 02 21:56:10 AST 2012"
Code I have have is
String dateStr = "Mon Jul 02 21:56:10 AST 2012";
DateFormat readFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy ");
DateFormat writeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = null;
try {
date = readFormat.parse(dateStr);
} catch (ParseException e) {
System.out.println("Error in parsing date ********");
}
String formattedDate = "";
if (date != null) {
formattedDate = writeFormat.format(date);
}
System.out.println("Formatted date is " + formattedDate);
Any idea where I am going wrong?
Update 1
I also tried with
DateFormat readFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy ");
^
but still same exception.
Your code works (with
z, and notZ), as soon as I specify that the date format should use the symbols of the English locale:As per eran, you also have extra space after yyyy:
yyyy "). Remove that extra space.