1 可以 建议配合Calendar使用
设置最大/小时间
设置当前显示时间
private Calendar startCal = Calendar.getInstance();
startCal.add(Calendar.MONTH, -6);//可以更改年,月,日 -- 提前日期
public void onClick(View v) {
String string = tvEnd.getText().toString().trim();
try {
endCal.setTime(DateFormatUtils.parseDate(string, "yyyy年MM月dd日"));
} catch (ParseException e) {
e.printStackTrace();
}
DatePickerDialog datePickerDialog = new DatePickerDialog(BusinessSearchDetailActivity.this, (view, year, monthOfYear, dayOfMonth) -> {
endCal.set(year, monthOfYear, dayOfMonth);
String dateString = DateFormatUtils.formatDate(endCal.getTime(), "yyyy年MM月dd日");
tvEnd.setText(dateString);
}, endCal.get(Calendar.YEAR), endCal.get(Calendar.MONTH), endCal.get(Calendar.DAY_OF_MONTH));
datePickerDialog.getDatePicker().setMinDate(startCal.getTimeInMillis());
datePickerDialog.show();
}