DatePickerDialog显示例如M加整数而不是月份名称

时间:2016-06-06 10:55:24

标签: android datepicker android-datepicker

DatePickerDialog显示M01代替January,例如......

这是我的代码:

@OnClick(R.id.dateTextView)
public void onDateTextViewClick(View view) {
    DatePickerDialog dialog = new DatePickerDialog(this,
            mDateListener, mYear, mMonth, mDay);
    dialog.getDatePicker().setMaxDate(mCalendar.getTimeInMillis());
    dialog.show();
}

private DatePickerDialog.OnDateSetListener mDateListener = new DatePickerDialog.OnDateSetListener() {
    @Override
    public void onDateSet(DatePicker arg0, int arg1, int arg2, int arg3) {
        // TODO Auto-generated method stub
        mYear = arg1;
        mMonth = arg2;
        mDay = arg3;
        showDate();
    }
};

如何更改?

3 个答案:

答案 0 :(得分:0)

只需通过月份否,您就会获得月份名称

 public String getMonth(int month) {
    return new DateFormatSymbols().getMonths()[month-1];
}

答案 1 :(得分:0)

public void getDate(EditText editText) {
    Calendar c = Calendar.getInstance(Locale.getDefault());
    int mYear = c.get(Calendar.YEAR);
    int mMonth = c.get(Calendar.MONTH);
    int mDay = c.get(Calendar.DAY_OF_MONTH);
    // date picker dialog
    datePickerDialog = new DatePickerDialog(CustomerProfileActivity.this,
            new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker view, int year,
                                      int monthOfYear, int dayOfMonth) {
                    selectedDate = year + "-" + (monthOfYear + 1) + "-" + dayOfMonth;

                    editText.setText(selectedDate);

                }
            }, mYear, mMonth, mDay);
    datePickerDialog.getDatePicker().setMaxDate(System.currentTimeMillis() - 1000);
    datePickerDialog.setTitle("Select Date");
    datePickerDialog.show();
}

只需在Calendar.getInstance中传递“ Locale.getDefault()”

答案 2 :(得分:0)

您错误地设置了本地值。像这样

// Don't copy past this  
Locale locale = new Locale("","");
Locale.setDefault(locale);

改为使用正确的语言代码和国家/地区代码。 例如:-

Locale locale = new Locale("en","GB");
Locale.setDefault(locale);