25

I want to know the current device time format, meaning 24 hour/ 12 hour format.

Please let me know how can I determine that.

Are there any API there to determine this?

Donald Duck
  • 8,409
  • 22
  • 75
  • 99
brig
  • 3,721
  • 12
  • 43
  • 61

3 Answers3

59

String value = android.provider.Settings.System.getString(context.getContentResolver(), android.provider.Settings.System.TIME_12_24);

Updated Answer, you should use this instead of the above, as above could give back a null value:

DateFormat.is24HourFormat(context)
MrJre
  • 7,082
  • 7
  • 53
  • 66
  • 3
    *Caution:* Using this can result in a null value being returned to your application. As specified in this answer http://stackoverflow.com/a/7922264/181211 , a better solution is `DateFormat.is24HourFormat()` . MrJre, I recommend updating your answer. – CrimsonX Aug 04 '14 at 19:07
  • This is what i was looking for. – andre719mv Oct 02 '16 at 20:59
  • Note that there are several classes called `DateFormat`, the one that you want is `android.text.format.DateFormat`. – Donald Duck Aug 10 '23 at 10:41
9

This may help you....

The link of the answer source: https://developer.android.com/reference/android/text/format/DateFormat.html#is24HourFormat(android.content.Context)

efkan
  • 12,991
  • 6
  • 73
  • 106
Farhan
  • 3,206
  • 14
  • 49
  • 62
0

I'm reporting something that seems an issue with Android 13: if the flag "use locale default" is on the device settings shows eg:

5:44 and the DateFormat.is24HourFormat(context) returns true

if I disable the option and leave the "Use 24 hour format" off it works properly.

Anyone has another solution to check if the clock on the status bar is 12 or 24h format?

Time is displayed in am/pm format Use locale default is on

Andrea Leganza
  • 447
  • 7
  • 7