문제

I am trying to parse some time strings like this:

String time_string = "10:00 AM";
SimpleDateFormat format = new SimpleDateFormat("hh:mm a");
Date date = null;
try {
    date = format.parse(time_string);
    // Do something with 'date'
} catch (ParseException e) {
    Log.w("Time", e.toString());
}

But the parser is failing with the exception:

java.text.ParseException: Unparseable date: "10:00 AM"

What I am doing wrong?

도움이 되었습니까?

해결책

The AM/PM marker may not match that of your default Locale Try

SimpleDateFormat format = new SimpleDateFormat("hh:mm a", Locale.ENGLISH);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top