Wie formatiere ich ein Datum in Großbuchstaben?
Posted: 13 Jan 2025, 15:54
Ich versuche, ein Datum folgendermaßen zu formatieren:
Das ist mein Code:
Aber ich möchte keine Split--Methode verwenden oder so etwas tun. Gibt es nicht ein Muster, das ich in den regulären Ausdruck einfügen kann, damit am Anfang jedes Worts ein Großbuchstabe steht?
UPDATE
Ich komme aus einem hispanischen Land, so etwas wie new Locale("es", "ES") Ich bekomme „martes 7, noviembre, 2013“, wenn ich „Martes 7, Noviembre, 2013“ brauche. .
Code: Select all
Monday 4, November, 2013
Code: Select all
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);
}
UPDATE
Ich komme aus einem hispanischen Land, so etwas wie new Locale("es", "ES") Ich bekomme „martes 7, noviembre, 2013“, wenn ich „Martes 7, Noviembre, 2013“ brauche. .