Read timestamp located in another region

"timestamp_utc": "۲۰۱۵-۱۱-۰۲T۱۸:۴۴:۳۴+۰۰:۰۰" 

is an attribute in JSON. How to parse this date? I tried the following code snippet.

 try { return new DateTime(dateStr, DateTimeZone.UTC); } catch (IllegalArgumentException e) { java.util.Locale locale = new java.util.Locale( "ar", "SA" ); DateTimeFormatter formatter = ISODateTimeFormat.dateTime().withLocale( locale ); return formatter.parseDateTime( dateStr ); } 

2015-05-11T11:31:47 Works great. However, ۲۰۱۵-۱۱-۰۲T۱۸:۴۴:۳۴+۰۰:۰۰ throws an IllegalArgumentException . Tried date parsing with other locales / formats. Bad luck.

 Locale list[] = DateFormat.getAvailableLocales(); for (Locale aLocale : list) { try{ DateTimeFormatter formatter = DateTimeFormat.forPattern( "yyyy-MM-dd'T'HH:mm:ssZ" ).withLocale(aLocale); System.out.println(formatter.parseDateTime( dateStr )); } catch(Exception e){ System.out.println("locale " + aLocale.toString() + " error"); } } 

Please help me.

+7
java date time jodatime arabic
source share
1 answer

Adding a non-Arabic character (T) made it a non-Arabic date (I got this idea while trying to translate it into google translate). Try below (the value of T is changed to <space> for both the input date and the template):

 public static void main (String[] args) throws java.lang.Exception { String ara = "۲۰۱۵-۱۱-۰۲ ۱۸:۴۴:۳۴+۰۰:۰۰"; for (Locale aLocale : DateFormat.getAvailableLocales()) { //Just to save time, not needed. if(aLocale.getLanguage() != "ar") continue; try{ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss+SS:SS", aLocale); System.out.println(sdf.parse( ara )); } catch(Exception e){ System.out.println("locale " + aLocale.toString() + " error"); } } } 
+2
source share

All Articles