Hunter Winchester
Hunter Winchester

Reputation: 305

TimePickerDialog to set format according to the device's time system

I'm developing a medication reminder android app. I have a problem on how to manipulate the time picker dialog so it will show the time depending on the device's time system. Si if the phone is in 12-hour format the time picker dialog should have am/pm selector. And if it is on the 24 hour format the time shown in time picker are from 00 - 24.

This code below is for 24-hour format. any idea on how to add the 12-hour format? And how to check what time format the phone is using. Thanks

TimePickerDialog.OnTimeSetListener t = new OnTimeSetListener() {
        @Override
        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
            DecimalFormat df = new DecimalFormat("00");
            timeHour = hourOfDay;
            timeMinute = minute;
            timeS = String.valueOf(df.format(hourOfDay)) + ":" + String.valueOf(df.format(minute));
            timeSelected.setText(timeS);
        }
    };

Upvotes: 0

Views: 444

Answers (1)

Nicolas Cortell
Nicolas Cortell

Reputation: 649

 is24HourFormat (Context context)

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

Source: http://developer.android.com/reference/android/text/format/DateFormat.html

Hope it helps

Upvotes: 1

Related Questions