Reputation: 43
While parsing string to date object using SimpleDateFormat
, I am getting below error.
java.text.ParseException: Unparseable date: "Tue, 29 Mar 2016 11:27:37 -0400"
The code I am using to parsed date is:
DateFormat df2 = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
I am able to parse dates like Mon, 13 Jun 2016 11:48:54 +0300
.
I noticed one thing that dates having +ve
timezone(+0300) are getting parsed but -ve
timezone(-0400) are not getting parsed.
Upvotes: 2
Views: 972
Reputation: 328737
I suspect the issue is that your default locale is not English (maybe German, which would explain why Mon works (Montag) but not Tue (Dienstag)?).
Just specify ENGLISH as a locale:
DateFormat df2 = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.ENGLISH);
Date date = df2.parse("Tue, 29 Mar 2016 11:27:37 -0400");
System.out.println(date); //prints Tue Mar 29 15:27:37 GMT 2016
The code above works fine on ideone and on my machine.
Upvotes: 1