开发者

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

开发者 https://www.devze.com 2022-12-12 02:09 出处:网络
I\'m currently using the following code to format time on Google Android: DateFormat.getDateTimeInstance().format(millis)

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 ho开发者_高级运维ur 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?


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.


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

"date" in millisec


Use the java.text.SimpleDateFormat class.

0

精彩评论

暂无评论...
验证码 换一张
取 消