问题
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:
Probably your default locale doesn't support English months in MMM. For example in Poland MMM supports "styczeń" but not "Jan" or "January"
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);
来源:https://stackoverflow.com/questions/19731752/convert-from-string-to-date-throws-unparseable-date-exception