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?

3 Answers 3

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)
3
  • 3
    Caution: Using this can result in a null value being returned to your application. As specified in this answer stackoverflow.com/a/7922264/181211 , a better solution is DateFormat.is24HourFormat() . MrJre, I recommend updating your answer.
    – CrimsonX
    Aug 4, 2014 at 19:07
  • This is what i was looking for.
    – andre719mv
    Oct 2, 2016 at 20:59
  • Note that there are several classes called DateFormat, the one that you want is android.text.format.DateFormat. Aug 10 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)

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.