Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Parse date in Simple date format in arabic locale?

i have date coming from server & is in the format = "2013-01-20T16:48:43" my application support Both Arabic & English Locale. But when i change the locale to Arabic the date is not parsing its giving me parse exception. till now what i have written is

private static Date parseJsonDate(final String string) throws Exception
    {
    final String change_Locale = Locale.getDefault().getISO3Language();
            if (change_Locale.equalsIgnoreCase("ara"))
            {

                System.out.println(":: Date :::" + string);
                final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", new Locale("ar"));

                System.out.println("new date " + format.parse(string));
                return format.parse(string);
like image 306
Jags Avatar asked Jan 21 '13 13:01

Jags


1 Answers

Do not parse your date into the Arabic it will give you error alwayz besides try as below by setting the Locale ENGLISH only.

final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH);
like image 58
GrIsHu Avatar answered Sep 24 '22 06:09

GrIsHu