문제

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top