Josus Praiser
Josus Praiser

Reputation: 65

How to get am/pm values from google material time picker in kotlin

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{
            }
        }

Upvotes: 1

Views: 859

Answers (2)

Tohedul
Tohedul

Reputation: 29

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

Upvotes: 0

Gabriele Mariotti
Gabriele Mariotti

Reputation: 363577

You don't need to get the time format.
Just use picker.hour. It returns the hour of day in the range [0, 23]

Upvotes: 2

Related Questions