I've got a number representing the day of the week (directly originating from a constant Calendar.MONDAY
for example). Now I'd like to get the user visible text of that day (using default locale of my mobile for the correct translation). I don't have a Calendar
instance yet, just the number!
Currently I'm using code below, but I've got the feeling this should be easier, or at least without instantiating a complete Calendar
(but I don't find a way to easily set the day_of_week to a Date).
private String LOCALE = Locale.getDefault();
private String FORMAT_DAY_OF_WEEK = "EEEE";
public convertDayOfWeekFromNumberToText(int dayOfWeekNumber) {
Calendar cal = Calendar.getInstance(LOCALE);
cal.set(Calendar.DAY_OF_WEEK, dayOfWeekNumber);
return new SimpleDateFormat(FORMAT_DAY_OF_WEEK, LOCALE).format(cal.getTime());
}
Is this really the easiest way to retrieve the text? And is there a better solution if you'd like to get the best performance?
ps. in case Java7 and Java8 solutions are different, please provide both.
Edit
Thanks to John16384 @ comments I've found a better solution (see answer). I've converted the util-method described above to 2 different methods (1 for short and 1 for long format). Additional solutions would still be appreciated!