I\'ve created a TimePicker in layout and I want it to show time with format 24h.
Can you help me? Thanks.
For Time picker Dialog
Timepicker dialog provides by android to select the time.
Java provides default functionality by passing is24HourView == true in TimePickerDialog constructor.
public TimePickerDialog(Context context, OnTimeSetListener listener, int hourOfDay, int minute,boolean is24HourView) {
this(context, 0, listener, hourOfDay, minute, is24HourView);
}
Pass true for 24 hours or pass false to set time picker dialog in AM-PM format.
for ex: (Kotlin)
private fun showTimePicker() {
val cal = Calendar.getInstance()
val dialog = TimePickerDialog(this, TimePickerDialog.OnTimeSetListener { view, hourOfDay, minute ->
Log.e("Time :","$hourOfDay:$minute")
}, cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), true) //here pass true for 24hrs view else false for AM-PM(12hrs view)
dialog.show()
}