SetMinDate () for DatePicker

I saw this question when stack overflowed in several places, but these answers do not work for me, so here I am :).

I need to set the minimum date of the date selection dynamically to the current date. My minimum API is 12.

I tried this:

Calendar minCalendar = Calendar.getInstance(); minCalendar.set(Calendar.MILLISECOND, minCalendar.MILLISECOND - 1000); DatePicker endDatePicker = (DatePicker) findViewById(R.id.datePicker2); endDatePicker.setMinDate(minCalendar.getTimeInMillis()); 

I do not get any errors, only the date of selection is not set to date. It is set for October 1964 ....

Please help me...

edited

I also tried this, but the same effect:

 endDatePicker.setMinDate(System.currentTimeMillis() - 1000); 
+4
source share
2 answers

From my similar questions and answers :

 // Calendar view is a cascade of bugs. // Work around that by explicitly disabling it. datePicker.setCalendarViewShown(false); 

If viewing your work calendar with a date picker is your priority, I would consider formatting the platform code and fixing bugs there.

+1
source

Try:

 Time now = new Time(); now.setToNow(); DatePicker endDatePicker = (DatePicker) findViewById(R.id.datePicker2); endDatePicker.setMinDate(now.toMillis(false)); 
0
source

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


All Articles