Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if the current locale uses 24-hour clock in Android?

Tags:

android

I have a time picker dialog in my app. This works just fine, but I'd like to switch between the 12-hour and 24-hour picker dialogs based on the current locale. How do I find out which clock is used?

The dialog itself is launched 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();
like image 281
manabreak Avatar asked Aug 10 '15 09:08

manabreak


1 Answers

Try this

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

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

See more about DateFormat here

like image 148
uday Avatar answered Nov 26 '22 14:11

uday