ereOn ereOn - 1 year ago 83
Android Question

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

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:


On my french localized phone. Almost fine.

How can I also output the hours, minutes and seconds parts of the
, using the user's locale ? I've been looking in the android documentation but couldn't find anything.

Many thanks.

Answer Source

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


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download