0

I'm using this Example to create DatePicker where the method of setMinDate takes the first parameter as Calendar instead of long, I want to execute this method datePicker.setMinDate(calendar.getTimeInMillis()- 1000); How to make the last date as Calendar instead of long without changing the method structure?

The structure of setMinDate in DatePickerDialog is:

public void setMinDate(Calendar calendar) {
    mMinDate = calendar;

    if (mDayPickerView != null) {
        mDayPickerView.onChange();
    }
}

Thanks in Advance.

Emy Alsabbagh
  • 287
  • 1
  • 3
  • 8

1 Answers1

0
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date date = (Date)formatter.parse("Your date"); //2016-02-22


datePicker.setsetMinDate(DateToCalendar(date));


public static Calendar DateToCalendar(Date date){ 
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal;
}
sasikumar
  • 12,540
  • 3
  • 28
  • 48
  • I want to use `calendar.getTimeInMillis()- 1000` to get the previous date, not want to use dateFormate becaus there is no specific format – Emy Alsabbagh Feb 22 '16 at 13:28
  • Convert String to Date without knowing the format of String.It's not possible.refer http://stackoverflow.com/questions/3707485/how-to-convert-string-to-date-without-knowing-the-format – sasikumar Feb 22 '16 at 13:37
  • also refer http://stackoverflow.com/questions/18893308/how-to-convert-string-to-date-without-knowing-the-format-of-string – sasikumar Feb 22 '16 at 13:37
  • I did it as `Date myDate = new Date(calender.getTimeInMillis() - 1000); datePicker.setMinDate(DateToCalendar(myDate)); ` – Emy Alsabbagh Feb 22 '16 at 13:51
  • Thanks for your Answer. – Emy Alsabbagh Feb 22 '16 at 13:51