How do I set AM/PM in a TimePicker?

后端 未结 5 1761
有刺的猬
有刺的猬 2020-12-18 18:40

I am using a TimePicker in my app. Whenever the user opens the screen with the TimePicker, I initialize it with the current time. When I do this, the TimePicker shows AM ins

5条回答
  •  隐瞒了意图╮
    2020-12-18 19:06

    public void onTimeSet(TimePickerDialog view, int hourOfDay, int minute) {
        if(hourOfDay>=0 && hourOfDay<12){
            time = hourOfDay + " : " + minute + " AM";
        } else {
            if(hourOfDay == 12){
                time = hourOfDay + " : " + minute + "PM";
            } else{
                hourOfDay = hourOfDay -12;
                time = hourOfDay + " : " + minute + "PM";
            }
        }
    
        deliveryTime.setText(time);
    }
    

提交回复
热议问题