How to check whether the current locale uses the 24-hour system in Android?

There is a time selector dialog box in my application. It works well, but I want to switch between 12 hour and 24-hour selector dialog boxes according to the current locale. How to find the clock used?

The dialog box itself starts like this:

boolean use24HourClock = true; // This i'd like to get from the locale
new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener()
{
    @Override
    public void onTimeSet(TimePicker view, int hourOfDay, int minute)
    {

    }
}, 12, 00, use24HourClock).show();

resolvent:

Try this

boolean use24HourClock = DateFormat.is24HourFormat(getApplicationContext());

Returns true if the user preference is set to 24-hour format

Learn more about dateformat here

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>