How to get datepicker value in date format?

后端 未结 5 1034
礼貌的吻别
礼貌的吻别 2021-02-08 05:55

I have a problem with my Datapicker

i use the code for getting date,month & year shown below

           DatePicker datePicker;
           datePicker         


        
5条回答
  •  名媛妹妹
    2021-02-08 06:23

    Starting from API level 12, DatePicker has public CalendarView getCalendarView (), using this view you can get the date:

    long dateTime = datePicker.getCalendarView().getDate();
    Date date = new Date(dateTime);
    

    Then format if needed:

    DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
    String formattedDate = dateFormat.format(date);
    

提交回复
热议问题