Reputation: 1716
I'm getting the time in my device, It's returning the time in GMT, and i'm converting it to Local .
The time i'm getting is for example : 23:00, When switching to Locale it returns in Arabic numbers, When i take the time from JSON, it doesn't switch it to Arabic .
Code :
private String GMTToLocal(String InputText){
SimpleDateFormat inputFormat = new SimpleDateFormat
("yyyy:M:dd kk:mm", Locale.US);
inputFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
SimpleDateFormat outputFormat =
new SimpleDateFormat("kk:mm");
// Adjust locale and zone appropriately
Date date = null;
try {
date = inputFormat.parse(InputText);
} catch (ParseException e) {
e.printStackTrace();
}
return outputFormat.format(date);
}
I tried the following, but didn't work :
String Tes2 = String.format(Locale.ENGLISH,Arabic_Letters_String);
The problem in short, i need the time in English letters/numbers, not in Arabic, this only happens when i get the time from my device, but if i get it from JSON, it takes it as English and return it as English, but from the device, it takes it as Arabic and return it as 0 value ( because Simpledateformat takes English only i guess ) .
Upvotes: 1
Views: 955
Reputation: 39863
SimpleDataFormat
has a constructor accepting a Locale
. By default the device locale is used, thus giving you arabic numbers.
SimpleDateFormat outputFormat = new SimpleDateFormat("kk:mm", Locale.US);
Upvotes: 3