我尝试将当前日期设置为DatePickerDialog
中的默认日期,
我看到这是如何设置当前日期:
final Calendar c = Calendar.getInstance();
year = c.get(Calendar.YEAR);
month = c.get(Calendar.MONTH);
day = c.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePickerDialog = new DatePickerDialog(getActivity(), onDateSetListener, year, month, day);
但是这段代码以MM / DD / YYYY的格式给我发送日期2/28/2000而不是04/16/2018(当前日期) 可能是什么问题?
答案 0 :(得分:0)
确保您的设备'当地时间'设置正确
答案 1 :(得分:0)
对于日期选择器尝试
public void pickdate(View button) {
// Get Current Date
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePickerDialog = new DatePickerDialog(this,
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
edittext_date.setText(dayOfMonth + "-" + (monthOfYear + 1) + "-" + year);
}
}, mYear, mMonth, mDay);
datePickerDialog.show();
}