How do I set AM/PM in a TimePicker?

后端 未结 5 1771
有刺的猬
有刺的猬 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:08

    Try this :

                Calendar calendar = Calendar.getInstance();
                calendar.set(0, 0, 0, hourOfDay, minute, 0);
                long timeInMillis = calendar.getTimeInMillis();
                java.text.DateFormat dateFormatter = new SimpleDateFormat("hh:mm a");
                Date date = new Date();
                date.setTime(timeInMillis);
                time.setText(dateFormatter.format(date));
    

提交回复
热议问题