I'm not sure what I am doing wrong? What is fromdate and what is todate? here is my code...
The max date works perfectly, so I'm really confused. It seems to me the new Date().getTime should return the right value or is it something else?
meetingDateButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
DatePickerDialog dpd = new DatePickerDialog(MapActivity.this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
SimpleDateFormat simpledateformat = new SimpleDateFormat("EEEE");
Date date = new Date(year, monthOfYear, dayOfMonth - 1);
String dayOfWeek = simpledateformat.format(date);
meetingSelectDate.setText(dayOfWeek + " " + (monthOfYear + 1) + "/" + dayOfMonth + "/" + year);
}
}, mYear, mMonth, mDay);
dpd.setTitle("Select Date:");
Date maxDate = new Date();
maxDate.setTime(new Date().getTime()+(86400000*7));
dpd.getDatePicker().setMaxDate(maxDate.getTime());
dpd.getDatePicker().setMinDate(new Date().getTime());
dpd.show();
}
});
dpd.getDatePicker().setMinDate(new Date().getTime() - 10000);
this is the answer, you have to subtract a little from the time for some reason?
You can get the Calendar instance,and set the time.
long minTimeMillis = System.currentTimeMillis() + 7 * 3600000;
final Calendar minDate = Calendar.getInstance();
minDate.setTimeInMillis(minTimeMillis);
minDate.set(Calendar.HOUR_OF_DAY, minDate.getMinimum(Calendar.HOUR_OF_DAY));
minDate.set(Calendar.MINUTE, minDate.getMinimum(Calendar.MINUTE));
minDate.set(Calendar.SECOND, minDate.getMinimum(Calendar.SECOND));
minDate.set(Calendar.MILLISECOND, minDate.getMinimum(Calendar.MILLISECOND));
dialog.getDatePicker().setMinDate(minDate.getTimeInMillis());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With