Mustansar Saeed
Mustansar Saeed

Reputation: 2790

Android: SimpleDateFormat ParseException in Arabic

I am parsing the date string but getting the parse exception in Arabic mode but works fine when the language in the app is set to English.

ParseException

06-15 19:16:07.607: W/System.err(27340): java.text.ParseException: Unparseable date: "6-15-2014" (at offset 2)
06-15 19:16:07.617: W/System.err(27340):    at java.text.DateFormat.parse(DateFormat.java:626)

But this is parsing fine in English.

Code

SimpleDateFormat format = new SimpleDateFormat(formatString);
        Date date = null;
        try {
            date = new SimpleDateFormat("MM-dd-yyyy").parse(detail.getContactBDate());
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

Can anyone please point out that what is missing? or in other languages what I can do to prevent these types of strings?

Thanks in advance

Upvotes: 0

Views: 1326

Answers (2)

Mustansar Saeed
Mustansar Saeed

Reputation: 2790

I am able to resolve the issue by setting the Locale.English as the default locale for date parsing after reading the Stackoverflow thread "Unparseable date" using SimpleDateFormatter with API code example.

Thanks,

Upvotes: 4

Frank ZHENG
Frank ZHENG

Reputation: 109

Are you sure "detail.getContactBDate()" would return the exact string '6-15-2014'?

I believe ,it has no relationship with your language setting. Because Java can handle internationalization very well.

Print out the string and recheck your argument.

Upvotes: 0

Related Questions