public void DateDialog() {
DatePickerDialog.OnDateSetListener listener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
long timeInMilliseconds = 0;
String givenDateString = "Tue Jun 23 16:08:28 GMT+05:30 2016";
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
try {
Date mDate = sdf.parse(givenDateString);
timeInMilliseconds = mDate.getTime();
System.out.println("Date in milli :: " + timeInMilliseconds);
} catch (ParseException e) {
e.printStackTrace();
}
view.setMaxDate(timeInMilliseconds);
datePicker.setText(dayOfMonth + "/" + monthOfYear + "/" + year);
}
};
DatePickerDialog dpDialog = new DatePickerDialog(this, listener, year, month, day);
dpDialog.show();
}
i have taken datepicker dialog. i want to restrict to select date from current date till its next 3 months
最佳答案
Calendar calendar = Calendar.getInstance();//get the current day
calendar.add(Calendar.MONTH,3);
long afterThreeMonthsinMilli=calendar.getTimeInMillis();
DatePickerDialog dpDialog = new DatePickerDialog(getActivity(), listener, mYear, mMonth, mDay);
dpDialog.getDatePicker().setMaxDate(afterThreeMonthsinMilli);
dpDialog.show();
关于android - 我已经采取了日期选择器对话框。我想限制选择从当前日期到 future 3 个月的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37523653/