如何获取dateformat以大写日期和月份
我的strings.xml中有这样的字符串:
<string name="day_format">EEEE</string><string name="date_format">dd. MMMM</string>
<string name="date_format_us">MMMM dd</string>
我在代码中像这样使用它们:
private void reinit() { mDayFormat = getString(R.string.day_format);
if (!DateFormat.is24HourFormat(this))
{
mDateFormat = getString(R.string.date_format_us);
}
else {
mDateFormat = getString(R.string.date_format);
}
mTimeFormat = is24HourMode(this) ? FORMAT_24_HOURS : FORMAT_12_HOURS;
mCalendar = Calendar.getInstance();
}
但是它以小写形式显示日期和月份,我希望将两者都大写。我该如何实现?
回答:
我像这样修复它:
final CharSequence date = DateFormat.format(mDateFormat, mCalendar); final CharSequence day = DateFormat.format(mDayFormat, mCalendar);
String time = (String) DateFormat.format(mTimeFormat, mCalendar);
RemoteViews views = new RemoteViews(getPackageName(), R.layout.clock2by2);
String days = new String(day.toString().substring(0,1).toUpperCase() + day.toString().substring(1));
String dates = new String(date.toString().substring(0,1).toUpperCase() + date.toString().substring(1));
views.setTextViewText(R.id.Day, days);
views.setTextViewText(R.id.Date, dates);
views.setImageViewBitmap(R.id.TimeView, buildUpdate(time));
以上是 如何获取dateformat以大写日期和月份 的全部内容, 来源链接: utcz.com/qa/416759.html