binding.etFirstTime.setOnClickListener{
val picker = MaterialTimePicker.Builder ()
.setTimeFormat(TimeFormat.CLOCK_12H)
. setHour( 12 )
.setMinute(10)
.setTitleText("Select Shop's Timing")
.build()
picker.showNow(childFragmentManager,"Time")
picker.addOnPositiveButtonClickListener{
}
}
Asked
Active
Viewed 696 times
1

Suraj Rao
- 29,388
- 11
- 94
- 103

Josus Praiser
- 29
- 4
-
Welcome to StackOverflow! Please take a look at [how to ask a good question](https://stackoverflow.com/help/how-to-ask) and provide some context to your question beyond just a block of code. – B-Schmidt Mar 18 '21 at 14:12
2 Answers
1
You don't need to get the time format.
Just use picker.hour
. It returns the hour of day in the range [0, 23]

Gabriele Mariotti
- 320,139
- 94
- 887
- 841
-
I want to access the am/pm selector, because I want to update my UI screen with the the selected hour, minute and am or pm in the text view, when selected by the user. – Josus Praiser Mar 19 '21 at 15:15
-
-
-
@GabrielMariotti so in a 12 hour format ,if a user selects 9th hour, then how can we change the UI as AM/PM? – Josus Praiser Mar 21 '21 at 16:49
-
@JosusPraiser No way. You just can have to hour in the range 0-23 – Gabriele Mariotti Mar 22 '21 at 11:14
0
Try this
val selectedTime = Calendar.getInstance()
selectedTime[0, 0, 0, picker.hour, picker.minute] = 0
val formattedTime = SimpleDateFormat("hh:mm:ss a", Locale.getDefault()).format(selectedTime.time)
Output example: 09:45:00 PM

Tohedul
- 29
- 1
- 7