Reputation: 1689
I get ParseException in second line of the folowing code:
SimpleDateFormat formatter = new SimpleDateFormat("d MMM yyyy kk:mm:ss zzz");
Date response = formatter.parse(dateStr);
Exception:
java.text.ParseException: Unparseable date: "1 Dec 2014 08:32:59 GMT" (at offset 2)
How to solve this?
Upvotes: 0
Views: 19133
Reputation: 1043
Why I receive java.text.ParseException: Unparseable date: "11 Jan 2015 15:56:00" (at offset 0) for 11 Jan 2015 15:56:00 +0100?!
SimpleDateFormat dateFormat = null;
Date pubDate = null;
try {
dateFormat = new SimpleDateFormat(
"EEE dd MMM yyyy HH:mm:ss Z", Locale.ENGLISH);
pubDate = dateFormat.parse(this.pubDate);
} catch (ParseException e) {
e.printStackTrace();
}
dateFormat = new SimpleDateFormat("dd/MM/yyy");
// convert to format dd/mm/yyyy
this.pubDate = dateFormat.format(pubDate);
Thank you so much!
Upvotes: 0
Reputation: 35597
You need to set the Locale.
SimpleDateFormat formatter = new SimpleDateFormat("d MMM yyyy kk:mm:ss zzz",
Locale.US);
Date response = formatter.parse("1 Dec 2014 08:32:59 GMT");
System.out.println(response);
Upvotes: 1