点击它我有一个按钮我正在加载一个datetimepicker
if(view == startDateButton){
DatePickerDialog dpd = new DatePickerDialog(this,
new OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
//dayOfMonth=Calendar.DAY_OF_MONTH;
//monthOfYear=Calendar.MONTH;
startDateText.setText(dayOfMonth + "/"
+ monthOfYear + "/" + year);
eventModel.setStartDate(dayOfMonth + "."
+ monthOfYear + "." + year);
}
}, Calendar.getInstance().YEAR,
Calendar.getInstance().MONTH, Calendar.getInstance().DATE);
dpd.show();
我希望日期时间选择器从当前日期开始
答案 0 :(得分:3)
您正在取错当前日期。您的IDE应该显示警告。
这是正确的方法:
Calendar calendar = Calendar.getInstance();
DatePickerDialog dpd = new DatePickerDialog(this,
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
//dayOfMonth=Calendar.DAY_OF_MONTH;
//monthOfYear=Calendar.MONTH;
setText(dayOfMonth + "/"
+ monthOfYear + "/" + year);
eventModel.setStartDate(dayOfMonth + "."
+ monthOfYear + "." + year);
}
}, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
calendar.get(Calendar.DAY_OF_MONTH));
dpd.show();