问题
I need to get a day string with only a day of week integer (example : 1 = monday, 5 = friday...), I don't have any date.
I know that I can define an array of string but I think there is a better solution by using a date format. Is it possible without having a date ?
回答1:
You can use the DayOfWeek enum to get a day by its number:
System.out.println(DayOfWeek.of(1).toString());
Output:
MONDAY
回答2:
Answer found thanks to shmosel. I am using the following :
DateFormatSymbols.getInstance().getWeekdays()
回答3:
You can simply Make Array of string days and get day by Integer using indexing.......
String[] strDays = new String[] { "Sunday", "Monday", "Tuesday","Wednesday", "Thursday","Friday", "Saturday" };
// Day_OF_WEEK starts from 1 while array index starts from 0
System.out.println("Current day is : " + strDays[0])
OutPut:
Sunday
来源:https://stackoverflow.com/questions/38990952/get-day-string-from-day-of-week-integer-java