kotlinformattimepicker

time format not changing in timepicker kotlin


So I used a timepicker in android studio Kotlin to receive input from the user as the following:

`

private lateinit var editTime : TimePicker

`

I did create the timepicker successfully, but whenever I show the result in a recyclerview the format **is as the following:

0:4

which actually is

12:04 AM

I don't know how to change the format, I tried this:

       var hour = editTime.hour.toString().format("%02d")
        val minute = editTime.minute.toString().format("%02d")

but it only worked with a timepicker dialog not the widget one.


Solution

  • you can try this

    var hour = String.format("%02d", editTime.hour)
    var min = String.format("%02d", editTime.minute)