time picker showing time like 4:7 instead of 04:07

前端 未结 8 1841
小蘑菇
小蘑菇 2021-02-05 05:41

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

8条回答
  •  失恋的感觉
    2021-02-05 06:23

    TimePickerDialog tpd = new TimePickerDialog(YourActivity.this, new 
    TimePickerDialog.OnTimeSetListener() {
    
        @Override
        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
            if (hourOfDay == 0) {
                hourOfDay = 12;
            }
            mEndTime = (String.format("%02d:%02d", hourOfDay, minute));
            //mEndTime = (hourOfDay + ":" + minute);
    
            mEditTextEnd.setText(mEndDate + " " + mEndTime + ":00");
        }
    }, mHourEnd, mMinuteEnd, true);
    tpd.show();
    

提交回复
热议问题