Convert from String to Date throws Unparseable date exception [duplicate]

匿名 (未验证) 提交于 2019-12-03 02:33:02

问题:

This question already has an answer here:

I want to convert a Date to a String but I have some problems. My code is this:

SimpleDateFormat formato = new SimpleDateFormat(             "EEE MMM dd HH:mm:ss z yyyy");      String hacer = "Fri Nov 01 10:30:02 PDT 2013";     Date test = null;     test = formato.parse( hacer);     System.out.println("prueba===>" + test); 

But nothing something is wrong eclipse shows me this error:

Unparseable date: "Fri Nov 01 10:30:02 PDT 2013" at java.text.DateFormat.parse(Unknown Source) 

some help?

回答1:

To change this In SimpleDateFormat you need to set locale which supports months written in English, for example

new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.ENGLISH); 


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