关于android日期格式的问题

时间:2011-06-17 02:13:51

标签: android

android有两个源代码,但我不明白它们的含义。 并且手机无法更改日期格式,日期格式始终为wday_month_day_no_year

mTimeFormat = DateFormat.getTimeFormat(getContext());
        mDateFormatString = getContext().getString(R.string.full_wday_month_day_no_year);
        refreshTimeAndDateDisplay();
        updateStatusLines();



public void onTimeChanged() {
        refreshTimeAndDateDisplay();
    }

    private void refreshTimeAndDateDisplay() {
        mDate.setText(DateFormat.format(mDateFormatString, new Date()));
    }

mDateFormatString = getContext().getString(R.string.full_wday_month_day_no_year);的含义是什么?

好吧,我改变了DateFormat,但在锁屏中,没有按照我设置的日期格式显示日期。所以我不知道它有什么问题。在lockSreen中,它总是按“full_wday_month_day_no_year”显示日期格式。

请帮我解决问题。

1 个答案:

答案 0 :(得分:2)

format()方法将字符串作为第一个参数。在这种特殊情况下,字符串在资源中定义,特别是在位于res/values/strings.xml的文件中,如

<string name="full_wday_month_day_no_year">E M d</string>

或类似的

DateFormat的引用:http://developer.android.com/reference/android/text/format/DateFormat.html

和字符串资源:http://developer.android.com/guide/topics/resources/string-resource.html

相关问题