我想显示一个格式星期一02但我显示格式

时间:2014-07-31 12:47:51

标签: android date datepicker

我正在使用datepicker dialog选择日期,我需要更改该日期后如何更改日期。
我怎样才能将所选日期更改为自定义日期(星期一02)。

  //calling this function in when i am selcted date
        protected Dialog onCreateDialog(int id) {
            switch (id) {
            case DATE_DIALOG_ID:
                // set date picker as current date
                Calendar c = Calendar.getInstance();
                c.setTime(new Date());
                return new DatePickerDialog(this, datePickerListener,
                        c.get(Calendar.YEAR), c.get(Calendar.MONTH),
                        c.get(Calendar.DATE));
            }
            return null;
        }
    //To set the selected date to textview here

        private DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener() {

            // when dialog box is closed, below method will be called.
            public void onDateSet(DatePicker view, int selectedYear,
                    int selectedMonth, int selectedDay) {
                mYear = selectedYear;
                mMonth = selectedMonth;
                mDay = selectedDay;

                StringBuilder selectedDate;

                selectedDate= new StringBuilder().append(mDay)
                        .append("/").append(mMonth + 1).append("/").append(mYear)
                        .append(" ");


                 SimpleDateFormat sdf1 = new SimpleDateFormat("dd/mm/yyyy");
                    SimpleDateFormat sdf2 = new SimpleDateFormat("EEE MMM dd");
                    String serverDate = "";

                    String editTextDate="";
                    editTextDate=selectedDate.toString();
                    try {
                        if(editTextDate != null && editTextDate.length() > 0){

                            Date output = sdf1.parse(editTextDate);
                            serverDate = sdf2.format(output);
                            System.out.println("serverDate: "+serverDate);

                        }
                    } catch (ParseException e) {
                        serverDate = "0";
                        e.printStackTrace();
                    }


                tvDisplayDate
                        .setText("Movies for: ".concat(serverDate));

            }
        };
    }

2 个答案:

答案 0 :(得分:0)

试试这个

private DatePickerDialog.OnDateSetListener 
     datePickerListener = new  DatePickerDialog.OnDateSetListener() 
{       
    public void onDateSet(DatePicker view, int selectedYear,
        int selectedMonth, int selectedDay) 
    {   
      SimpleDateFormat simpledateformat = new SimpleDateFormat("EEEE");
      Date date = new Date(selectedYear, selectedMonth, selectedDay-1);
      String dayOfWeek = simpledateformat.format(date);
    }
}

答案 1 :(得分:0)

使用这样的日历

Calendar calender = Calendar.getInstance();
Log.d("Current day:" + calender.get(Calendar.DAY_OF_WEEK));