Reputation: 1625
I have been trying to parse a string to a Date and i have searched this everywhere and could not find a solution to it. I have a String formatted. And when I try to parse it it always throws an exception though i have tried setting Locale.English also and giving the date pattern (obviously). And my Date pattern is "Wed, 29 Jun 2016 16:16:32 +0000". Thanks in advance for help.
dateFormat = new SimpleDateFormat("EEE, DD MMM yyyy HH:mm:ss 'Z'", Locale.ENGLISH);
try {
String dateA = "Wed, 29 Jun 2016 16:16:32 +0000";
String dateB = "Wed, 29 Jun 2016 16:04:54 +0000";
Date parsedDateA = dateFormat.parse(dateA);
Date parsedDateB = dateFormat.parse(dateB);
if (parsedDateA .equals(parsedDateB ) || parsedDateA .before(parsedDateB )) {
//Do some work here
}
} catch (ParseException e) {
e.printStackTrace();
}
Upvotes: 1
Views: 320