I am using the DatePicker
for my application. I want to get the date that I have selected (on the DatePicker
), but it\'s not returning the selected
private void openCalendar() {
DatePickerDialog dialog = new DatePickerDialog(getContext(), (view, year, month, dayOfMonth) -> {
date = getDateString(year, month, dayOfMonth);
}, mYear, mMonth, mDay);
dialog.show();
}
private String getDateString(int year, int mMonth, int mDay) {
Calendar calendar = Calendar.getInstance();
calendar.set(year, mMonth, mDay);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
return dateFormat.format(calendar.getTime());
}