我正在使用日期和时间对话框来获取当前日期和时间。但我的问题是我想限制我的日期选择器从当前日期开始,其次我的时间选择器以24小时格式显示,我想显示它:例如下午2:00。我的代码如下,请帮我弄明白该怎么做。
public void showTime(){
new TimePickerDialog(VirtualBodyGuardActivity.this,
new TimePickerDialog.OnTimeSetListener() {
@Override public void onTimeSet(TimePicker view,
int h, int min) {
cal.set(Calendar.HOUR_OF_DAY, h);
cal.set(Calendar.MINUTE, min);
cal.set(Calendar.SECOND, 0);
sendDate = cal.getTime();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
public void showTime(){
new TimePickerDialog(VirtualBodyGuardActivity.this,
new TimePickerDialog.OnTimeSetListener() {
@Override public void onTimeSet(TimePicker view,
int h, int min) {
cal.set(Calendar.HOUR_OF_DAY, h);
cal.set(Calendar.MINUTE, min);
cal.set(Calendar.SECOND, 0);
sendDate = cal.getTime();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
"EE, MMMM dd, yyyy hh:mm a");
mEdtTimePicker.setText(simpleDateFormat.format(sendDate).toString());
}
}, cal.get(Calendar.HOUR_OF_DAY),
cal.get(Calendar.MINUTE), true).show();
}
public void showDateTime(){
Date value = new Date();
cal.setTime(value);
new DatePickerDialog(this,
new DatePickerDialog.OnDateSetListener() {
@Override public void onDateSet(DatePicker view,
int y, int m, int d) {
cal.set(Calendar.YEAR, y);
cal.set(Calendar.MONTH, m);
cal.set(Calendar.DAY_OF_MONTH, d);
showTime();
// now show the time picker
}
}, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH),
cal.get(Calendar.DAY_OF_MONTH)).show();
} "EE, MMMM dd, yyyy hh:mm a");
mFormatter.parse(mDateSelected);
;
mEdtTimePicker.setText(simpleDateFormat.format(sendDate).toString());
}
}, cal.get(Calendar.HOUR_OF_DAY),
cal.get(Calendar.MINUTE), true).show();
}
public void showDateTime(){
Date value = new Date();
cal.setTime(value);
new DatePickerDialog(this,
new DatePickerDialog.OnDateSetListener() {
@Override public void onDateSet(DatePicker view,
int y, int m, int d) {
cal.set(Calendar.YEAR, y);
cal.set(Calendar.MONTH, m);
cal.set(Calendar.DAY_OF_MONTH, d);
showTime();
// now show the time picker
}
}, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH),
cal.get(Calendar.DAY_OF_MONTH)).show();
}