How can I display the time in the current app locale using Calendar?
For instance I’d like “14:35” in french, and “2:35 pm” in english.
When my default locale is french, I get the time in english:
Calendar cal;
cal.setTimeInMillis(System.currentTimeMillis());
String displayTime = cal.getTime(); //Wed Mar 28 13:41:00 HAEC 2012
From the doc, Calendar is “locale aware”. Do I have to set the locale manually? How?
I could use SimpleDateFormat, but I’d have to set a pattern with the hour format as ‘h’ or ‘k’ manually according to whether I want hours in day or am/pm.
Basically: is there any locale-aware method to get the time as hours:minutes?
Thanks
No, but you can ask android if the mobile is set in 24hours format or AM/PM and compile the patter for the
SimpleDateFormataccordingly .