【问题标题】:DatePickerDialog shows e.g. M plus integer instead of month nameDatePickerDialog 显示例如M 加整数而不是月份名称
【发布时间】:2016-06-06 10:55:24
【问题描述】:

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();
    }
};

我怎样才能改变它?

【问题讨论】:

  • 面临同样的问题,仅在牛轧糖上方显示!!找到解决方案了吗?

标签: android datepicker android-datepicker


【解决方案1】:

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

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

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

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

【讨论】:

    【解决方案2】:

    只需传递月份编号,您将获得月份名称

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

    【讨论】:

    • 请告诉我们它是如何工作的尝试通过日期选择器但没有工作...解释你如何使用这个方法
    【解决方案3】:
    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()”

    【讨论】:

      猜你喜欢
      • 2020-04-03
      • 1970-01-01
      • 1970-01-01
      • 2011-12-22
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多