Android format date to MM-DD-YYYY from Datepicker

后端 未结 10 1763
轻奢々
轻奢々 2020-12-16 11:46

I have a datepicker. My app is pushing a notification. I want to display the date in 01-07-2013 MM-dd-yyyy format. Please check my code below:

 //---Button v         


        
10条回答
  •  庸人自扰
    2020-12-16 12:12

    just use this code..

     date.setOnClickListener(new OnClickListener() 
            {
    
                public void onClick(View v) 
                {
                    DatePickerDialog dateDlg = new DatePickerDialog(New_Quote_Activity.this, new DatePickerDialog.OnDateSetListener() 
                    {
    
                             public void onDateSet(DatePicker view, int year,int monthOfYear, int dayOfMonth) 
                             {
                                    CharSequence strDate = null;
                                        Time chosenDate = new Time();        
                                        chosenDate.set(dayOfMonth, monthOfYear, year);
                                        long dtDob = chosenDate.toMillis(true);
    
                                        strDate = DateFormat.format("MM/dd/yyyy", dtDob);
    
                                        txtDate.setText(strDate);
                            }}, year,month,day);
    
                          dateDlg.show();
                   }
            });
    

提交回复
热议问题