2 ssummeraw ssummeraw 于 2013.08.26 17:16 提问

数据库中检索日期出现的错误

我用下面的代码创建DatePickerDialog,我想在数据库中检索用户的出生日期,当我打开dateDialog时,应该是用户的出生日期。现在的日期不对,应该是9月份,结果出来是10月份。这是什么原因造成的,如何改代码啊?

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {

    case DATE_DIALOG_ID:
        return new DatePickerDialog(this,
            mDateSetListener,
            mYear, mMonth, mDay);
    }
    return null;
}
@Override
protected void onPrepareDialog(int id, Dialog dialog) {
    switch (id) {

    case DATE_DIALOG_ID:
        ((DatePickerDialog) dialog).updateDate(mYear, mMonth, mDay);

        break;
    }
}   
private void updateDisplay() {
    dateText.setText(
        new StringBuilder()
        // Month is 0 based so add 1

        .append(mMonth +1).append("/")
        .append(mDay).append("/")
        .append(mYear).append(" "));
}

DatePickerDialog.OnDateSetListener mDateSetListener =
        new DatePickerDialog.OnDateSetListener() {

        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear,
                int dayOfMonth) {
            mYear = year;
            mMonth = monthOfYear;
            mDay = dayOfMonth;
            dob1 = (monthOfYear + "/" + dayOfMonth + "/" + year);
            if(maxYear - mYear <= 12){
                alertMessage = "User must be above age of 12.";
                dialogBox();
                year = mYear;
            }
            else{
                updateDisplay();
            }
        }
    };
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!