我想在Activity
(默认设置)中设置当前日期,用户可以通过单击日期选择器来配置日期。但有些设备显示额外一个月,日期选择器对话框也显示一个月额外。能帮我解决这个问题吗
public void setCurrentDateOnButton()
{
Log.d(LogActivityTagNames.SCHEDULE_ACTIVITY," Entered into setCurrentDateOnButton()");
final Calendar c = Calendar.getInstance();
myear = c.get(Calendar.YEAR);
mmonth = c.get(Calendar.MONTH)+1;
mday = c.get(Calendar.DAY_OF_MONTH);
String month = QuickeRideAppUtils.formatDateTime(mmonth);
String day = QuickeRideAppUtils.formatDateTime(mday);
date.setText(new StringBuilder()
.append(day).append("-").append(month).append("-")
.append(myear).append(" "));
}
...
private DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener()
{
public void onDateSet(DatePicker view, int selectedYear,int selectedMonth, int selectedDay)
{
myear = selectedYear;
mmonth = selectedMonth;
mday = selectedDay;
String month = QuickeRideAppUtils.formatDateTime(mmonth);
String day = QuickeRideAppUtils.formatDateTime(mday);
date.setText(new StringBuilder().append(day).append("-").append(month).append("-").append(myear).append(" "));
}
};
答案 0 :(得分:0)
从此行mmonth = c.get(Calendar.MONTH)+1;
删除+1只需将其写为
mmonth = c.get(Calendar.MONTH)
date.setText(new StringBuilder()
.append(day).append("-").append(month).append("-")
.append(myear).append(" "));