ParseException: Unparseable date: “Wed Mar 30 00:00:00 GMT+05:30 2016” (at offset 4)

社会主义新天地 提交于 2020-05-11 06:44:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!