如何获取dateformat以大写日期和月份 [英] how to get dateformat to capitalize month and day
本文介绍了如何获取dateformat以大写日期和月份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的strings.xml中有这样的字符串:
I have my strings like so in my strings.xml:
<string name="day_format">EEEE</string>
<string name="date_format">dd. MMMM</string>
<string name="date_format_us">MMMM dd</string>
我在代码中这样使用它们:
And I use them like this in the code:
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();
}
但是它以小写形式显示日期和月份,我希望它将两者都大写。我该如何实现呢?
But it displays the day and the month in lowercase, and I want it to capitalize both. How can I achieve that?
推荐答案
我将其固定为:
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以大写日期和月份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文