Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set minDate in DatePickerDialog to be after 2 days

I created a DatePickerDialog in my Activity, and I am trying to set the minDate to after 2 days.

For example, today is 25/5/2015, and I want the minDate to be: 27/5/2015

This is the code:

final DatePickerDialog dpd = new DatePickerDialog(TestActivity.this,listener,calendar.get(Calendar.YEAR)
                ,calendar.get(Calendar.MONTH)
                ,calendar.get(Calendar.DAY_OF_MONTH));
        DatePicker dp = dpd.getDatePicker();

        dp.setMinDate(//I want to set it to after 2 days);

I tried this but I got an error:

dp.setMinDate(System.currentTimeMillis() + 2000);

So how can it be done ?

Thanks.

like image 232
Michael Avatar asked Jan 08 '23 07:01

Michael


1 Answers

Try this:

Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_YEAR, 2);
dp.setMinDate(cal.getTimeInMillis()); // where  DatePicker dp
like image 183
Mithun Avatar answered Jan 16 '23 17:01

Mithun