I have a time picker function which sets time in an EditText . But the format it shows is not suitable. for example for 04:07pm is shown as 4:7. whenever the digit in time is l
You can check if the hours and minutes are less then ten. If so, you just add a "0" infront of that specific string. Just modify your code like this:
@Override
public void onTimeSet(TimePicker view, int hourOfDay,
int minute) {
// Display Selected time in textbox
String hourString;
if (hourOfDay < 10)
hourString = "0" + hourOfDay;
else
hourString = "" +hourOfDay;
String minuteSting;
if (minute < 10)
minuteSting = "0" + minute;
else
minuteSting = "" +minute;
txtTime1.setText(hourString + ":" + minuteSting);
}