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{
}
}
您不需要获取时间格式
只需使用picker.hour
。它返回一天中[0,23]范围内的小时
试试这个
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)
输出示例:09:45:00 PM