Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting time on Android, while following preferences (24 hr clock vs. AM/PM, etc..)

I'm currently using the following code to format time on Google Android:

DateFormat.getDateTimeInstance().format(millis)

While this code honors my timezone and locale settings, it ignores the '24 hour mode' setting in system preferences, always returning time in AM/PM. Is there any way to get time in the same format as that on the status bar?

like image 371
Melllvar Avatar asked Nov 16 '09 06:11

Melllvar


2 Answers

In theory (never tried this yet), you can use

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

To get formatters based on your settings. YMMV.

like image 200
Nate Avatar answered Oct 10 '22 16:10

Nate


SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm");
df.format(new Date(date));

"date" in millisec

like image 44
embo Avatar answered Oct 10 '22 15:10

embo