So I tried searching for ways to get the output of the TimePicker dialog to set a TextView as HH:mm AM/PM (ex: 8:00 AM). I know there is stuff out there, but I couldn't find it exactly what fit. I took answers that got me close (shout out to Faraz Ahmed from this question: and added my own 'spin' to it. Just posting in hopes that it will help someone in the same situation.
Below will take the input in onTimeSet and format it to this: HH:mm AM/PM.
inal Calendar myCalendar = Calendar.getInstance();
String am_pm = "";
myCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
myCalendar.set(Calendar.MINUTE, minute);
if (myCalendar.get(Calendar.AM_PM) == Calendar.AM)
am_pm = "AM";
else if (myCalendar.get(Calendar.AM_PM) == Calendar.PM)
am_pm = "PM";
String strHrsToShow = (myCalendar.get(Calendar.HOUR) == 0) ? "12" : myCalendar.get(Calendar.HOUR) + "";
//UIHelper.showLongToastInCenter(context, strHrsToShow + ":" + myCalendar.get(Calendar.MINUTE) + " " + am_pm);
if (minute == 0) {
String mZeroMinute = "00";
mSessionEndTimeTV.setText(strHrsToShow + ":" + mZeroMinute + " " + am_pm);
} else {
mSessionEndTimeTV.setText(strHrsToShow + ":" + myCalendar.get(Calendar.MINUTE) + " " + am_pm);
Please see above:
inal Calendar myCalendar = Calendar.getInstance();
String am_pm = "";
myCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
myCalendar.set(Calendar.MINUTE, minute);
if (myCalendar.get(Calendar.AM_PM) == Calendar.AM)
am_pm = "AM";
else if (myCalendar.get(Calendar.AM_PM) == Calendar.PM)
am_pm = "PM";
String strHrsToShow = (myCalendar.get(Calendar.HOUR) == 0) ? "12" : myCalendar.get(Calendar.HOUR) + "";
//UIHelper.showLongToastInCenter(context, strHrsToShow + ":" + myCalendar.get(Calendar.MINUTE) + " " + am_pm);
if (minute == 0) {
String mZeroMinute = "00";
mSessionEndTimeTV.setText(strHrsToShow + ":" + mZeroMinute + " " + am_pm);
} else {
mSessionEndTimeTV.setText(strHrsToShow + ":" + myCalendar.get(Calendar.MINUTE) + " " + am_pm);