时间选择器格式

Time picker format

我在 Android 项目中使用时间选择器。但它显示 8.1 而不是 8.01。我正在使用代码:

public class TimePickerFragment extends DialogFragment implements
        TimePickerDialog.OnTimeSetListener {

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

        return new TimePickerDialog(getActivity(), this, hour, minute,
                DateFormat.is24HourFormat(getActivity()));
    }

    public void onTimeSet(TimePicker view, int hour, int minute) {
        timerFlag = true;
        minuteP = minute;
        hourP = hour;
        flagData.setTimePicker(timerFlag);
        setTime(timePicker, hour, minute);

    }
}

您必须检查分钟是否小于下面给出的 10.Code...

    String minuteFormatter = "";
    if (minute < 10) {
        minuteFormatter = "0" + minute;
    } else {
        minuteFormatter = String.valueOf(minute);
    }
    StringBuilder Time = new StringBuilder().append(hour).append(" : ")
            .append(minuteFormatter);

String.format("%02d:%02d",hour,minute)