效果:
使用方法:
// 获取当前时间 Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("GMT+8")); if (mHour == -1 && mMinute == -1) { mHour = calendar.get(Calendar.HOUR_OF_DAY); mMinute = calendar.get(Calendar.MINUTE); } mTimePicker = (TimePicker) findViewById(R.id.timePicker); mTimePicker.setCurrentHour(mHour); mTimePicker.setCurrentMinute(mMinute); mTimePicker .setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { @Override public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { mHour = hourOfDay; mMinute = minute; } });
原文:http://my.oschina.net/u/660536/blog/375878