How to get dateformat for month and day header
I have my lines, as in my .xml lines:
<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 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 month in lower case, and I want it to use both values. How can i achieve this?
I fixed it like this:
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));
You can use WordUtils.capitalize(..)from commons-lang (in the result line)
(this is if you want to use capital letters - for example, only the first letter is in upper case. Otherwise, you can use simpyl .toUpperCase())
. , WordUtils , .