String to Date conversion (everything seems good but fail)
-
18-06-2021 - |
문제
How to parse this string?
"Mon Jul 02 13:49:16 CEST 2012"
String Date = "Mon Jul 02 13:11:38 CEST 2012";
DateFormat formatter;
Date convertedDate= new Date();
formatter = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy");
try {
convertedDate = (Date) formatter.parse(Date);
} catch (ParseException ex) {
Logger.getLogger(ItemRecTestCases.class.getName()).log(Level.SEVERE, null, ex);
}
Dont work..."java.text.ParseException: Unparseable date:
"
해결책
You need to set the locale :
formatter = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy", Locale.ENGLISH);
Or else "Mon" cannot be parsed as "monday".
다른 팁
The Locale needs to be specified:
formatter = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy", Locale.US);
제휴하지 않습니다 StackOverflow