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

前端 未结 8 1856
小蘑菇
小蘑菇 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:37

    i might be little late to the party but this will surely help to someone else.

     private String getTime(int hr, int min) {
        Time tme = new Time(hr, min, 0);//seconds by default set to zero
        Format formatter;
        formatter = new SimpleDateFormat("h:mm a");
        return formatter.format(tme);
    }
    

提交回复
热议问题