Set minimum date for DatePickerDialog, getting IllegalArgumentException Fromdate, not preceding toDate

I'm not sure what I'm doing wrong? What is fromdate and what is date? here is my code ...

The maximum date works fine, so I'm really confused. It seems to me that the new Date (). Should GetTime return the correct 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(); } }); 
+6
source share
2 answers

dpd.getDatePicker (). setMinDate (new date (). getTime () - 10000);

This is the answer, you have to subtract a little because of time for some reason?

+16
source

You can get a copy of the calendar 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()); 
0
source

Source: https://habr.com/ru/post/972999/


All Articles