I'm trying to format a date in this way:
Monday 4, November, 2013
This is my code:
private static String formatDate(Date date) {
Calendar calenDate = Calendar.getInstance();
calenDate.setTime(date);
Calendar today = Calendar.getInstance();
if (calenDate.get(Calendar.DAY_OF_MONTH) == today.get(Calendar.DAY_OF_MONTH)) {
return "Today";
}
today.roll(Calendar.DAY_OF_MONTH, -1);
if (calenDate.get(Calendar.DAY_OF_MONTH) == today.get(Calendar.DAY_OF_MONTH)) {
return "Yesterday";
}
// Guess what buddy
SimpleDateFormat sdf = new SimpleDateFormat("EEEEE d, MMMMM, yyyy");
// This prints "monday 4, november, 2013" ALL in lowercase
return sdf.format(date);
}
But I don't want to use some split
method or do something like that. Isn't there some pattern that I can include in the regexp to make it be uppercase at the begin of each word?
UPDATE
I'm from a hispanic country, something like new Locale("es", "ES")
I get "martes 7, noviembre, 2013" when what I need is "Martes 7, Noviembre, 2013".
Best Answer
You can change the strings that
SimpleDateFormat
outputs by setting theDateFormatSymbols
it uses. The official tutorial includes an example of this: http://docs.oracle.com/javase/tutorial/i18n/format/dateFormatSymbols.htmlReproduction of the example from the tutorial, applied to the "short weekdays":