I've created a TimePicker in layout and I want it to show time with format 24h.
Can you help me? Thanks.
Timepicker dialog provides by android to select the time. Java provides default functionality by passing is24HourView == true in TimePickerDialog constructor. Pass true for 24 hours or pass false to set time picker dialog in AM-PM format.
You can get AM/PM from Timepicker using following method. Timepicker is a viewgroup. That's why we can get its child view index 2 which demonstrates AM/PM is actually a button. So we can get its text.
The time can be selected by hour, minute, and AM/PM picker columns. The AM/PM mode is determined by either explicitly setting the current mode through setIs24Hour(boolean) or the widget attribute is24HourFormat (true for 24-hour mode, false for 12-hour mode).
TimePicker
is a view for selecting the time of day, in either 24 hour or AM/PM mode. You can use setIs24HourView(true)
method with TimePicker.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With