How to get date from date picker in android?

前端 未结 7 1588
眼角桃花
眼角桃花 2021-01-13 10:29

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

7条回答
  •  广开言路
    2021-01-13 11:20

    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());
    }
    

提交回复
热议问题