Android DatePicker with current date

后端 未结 2 1179
既然无缘
既然无缘 2021-01-16 03:06

I am not getting current date in my datePickerDialog. Always x.xx.1900 :/

Here is my code:

    Calendar c = Calendar.getInstance();         


        
相关标签:
2条回答
  • 2021-01-16 03:50

    the constructor of DatePickerDialog is

    public DatePickerDialog (Context context, DatePickerDialog.OnDateSetListener callBack, int year, int monthOfYear, int dayOfMonth)
    

    You should use this :

    Calendar c = Calendar.getInstance();
    
    c.setTimeInMillis(System.currentTimeMillis());
    int y = c.get(Calendar.YEAR);
    int m = c.get(Calendar.MONTH);
    int d = c.get(Calendar.DAY_OF_MONTH);
    
    return new DatePickerDialog(getActivity(),this,y,m,d);
    
    0 讨论(0)
  • 2021-01-16 03:53

    Use This to get the The Latest Date

    public String getDisplayDate(){
        return (dt.getDate()+"/"+(dt.getMonth()+1)+"/"+(dt.getYear()+1900));
    }
    
    0 讨论(0)
提交回复
热议问题