问题
Im trying parse a String with a date to convert it into a Date format. Strings are in the following format.
Wed Mar 30 00:00:00 GMT+05:30 2016
But when im parsing the String i get a error saying,
java.text.ParseException: Unparseable date: "Wed Mar 30 00:00:00 GMT+05:30 2016" (at offset 4)
below is a part of my code. How do i avoid this error? Any help would be appreciated.
SimpleDateFormat sdf3 = new SimpleDateFormat("EEE MM dd kk:mm:ss zzzz yyyy",Locale.ENGLISH);
for(int i=0 ; i <jArr.length() ; i++){
String tempDate = jArr.get(i).toString();
dateList.add(tempDate);
}
try{
Date d1 = sdf3.parse(dateList.get(0));
}catch (Exception e){ e.printStackTrace(); }
回答1:
Check this once. working fine for me
SimpleDateFormat sdf3 = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH);
Date d1 = null;
try{
d1 = sdf3.parse("Wed Mar 30 00:00:00 GMT+05:30 2016");
}catch (Exception e){ e.printStackTrace(); }
System.out.println("check..." + d1);
回答2:
Wed Mar 30 00:00:00 GMT+05:30 2016
EEE MM dd kk:mm:ss zzzz yyyy
Your data doesn't match your pattern. To get it working, update your pattern to
"EEE MMM dd kk:mm:ss zXXX yyyy"
PS: here is a handy tool to test your patterns.
来源:https://stackoverflow.com/questions/36309255/parseexception-unparseable-date-wed-mar-30-000000-gmt0530-2016-at-offse