I'm new to both Java and Android development so this might be a stupid question, but I've been searching for days now and can't find a solution:
I try to output a java.util.Date
depending on the user's locale.
Searching on StackOverflow lead me to this:
java.util.Date date = new Date(); String dateString = DateFormat.getDateFormat(getApplicationContext()).format(date);
This outputs:
20/02/2011
On my french localized phone. Almost fine.
How can I also output the hours, minutes and seconds parts of the Date
, using the user's locale ? I've been looking in the android documentation but couldn't find anything.
Many thanks.
Formatting Dates and Times Based On Locales (LOCALE-DATE, LOCALE-TIME) A date or time can be formatted in a culturally appropriate way by using LOCALE functions.
Use "zzz" instead of "ZZZ": "Z" is the symbol for an RFC822 time zone. DateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
Under format click the Change date and time formats link. Use the Short name drop-down menu to select the date format you want to see in the Taskbar. Use the Short time drop-down menu to select the time format you want to see in the Taskbar.
Use android.text.format.DateFormat.getTimeFormat()
ref: http://developer.android.com/reference/android/text/format/DateFormat.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With