Ahmed na Ahmed na - 3 months ago 17
Android Question

convert string yyyy-MM-dd into date format with phone language right to left (Arabic)

This is my code:

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String exp_date="2015-08-28";
try {
Log.v("dateformat111","is "+exp_date);
Date exp_dateFormated = format.parse(exp_date);
Log.v("dateformat111","is "+exp_dateFormated);
} catch (ParseException e) {
Log.v("dateformat111","did not found date");

And the catch is being called so something went wrong

Log :

09-24 12:21:34.931 19014-19014/? V/dateformat111﹕ did not found date

Exception :

java.text.ParseException: Unparseable date: "2015-08-28"

Not a duplicate of How to parse a date?
the string I'm parsing is the same format of SimpleDateFormat
"yyyy-MM-dd" ,"2015-08-28"

I found out what is causing the exception
with English (ltr) as phone language my code works
but when change it to Arabic (rtl) the exception is thrown, why is that?


Your Problem is due to invalid date in locale. try changing your locale as below.

 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd",Locale.US); 

It will work.