Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date and time formatting depending on locale

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.

like image 997
ereOn Avatar asked Feb 20 '11 18:02

ereOn


People also ask

What is locale time?

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.

How do you display timezone in date format?

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");

Can we change the format of date and time?

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.


1 Answers

Use android.text.format.DateFormat.getTimeFormat()

ref: http://developer.android.com/reference/android/text/format/DateFormat.html

like image 109
Tiago Avatar answered Oct 08 '22 23:10

Tiago