这里我使用黑莓8520来显示时间选择器。我想将时间设置为10:00:00,直到timepickerstarts改变模拟器中的时间
public void run()
{
//create timepicker by using this method
//by using this simpledateformat we set time format
SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mm:ss aa");
DateTimePicker datepicker = DateTimePicker.createInstance(Calendar.getInstance(),null,"hh:mm:ss aa");
datepicker.doModal();
StringBuffer datestrTime=new StringBuffer();
//by using this method we get date from system date&time
Calendar cal = datepicker.getDateTime();
timeFormat.format(cal,datestrTime, null);
// we are taking the current time from the system and displaying in the label field
time_picker.setText(datestrTime.toString());
}
答案 0 :(得分:1)
使用以下代码:
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR,10);
cal.set(Calendar.MINUTE,00);
cal.set(Calendar.SECOND,00);
datepicker.setDateTime(cal);
datepicker.doModal();