标签:
1 /** 2 * 设置时间选择器 3 */ 4 private void setTimePickerDialog() { 5 Calendar mCalendar = Calendar.getInstance(); 6 mCalendar.setTimeInMillis(System.currentTimeMillis()); 7 final int hour = mCalendar.get(Calendar.HOUR_OF_DAY); 8 int minute = mCalendar.get(Calendar.MINUTE); 9 new TimePickerDialog(this,new TimePickerDialog.OnTimeSetListener() { 10 @Override 11 public void onTimeSet(TimePicker view,int hourOfDay,int minute) 12 { 13 //使用三元运算符来满足需求 14 String sHour = hour < 10 ? "0" + hour : "" + hour; 15 String sMinutes = minute < 10 ? "0" + minute : "" 16 + minute; 17 //指定一个textview来显示时间 18 textview.setText(sHour + ":" + sMinutes); 19 } 20 }, hour, minute, true).show(); 21 }
TimePickerDialog时间选择器,选择0-9分钟时,显示为10:0 9:1的样式,要改成 10:00 09:01的样式 的解决方式
标签:
原文地址:http://www.cnblogs.com/cloud9527/p/4881064.html