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 ?
You can use the DayOfWeek
enum to get a day by its number:
System.out.println(DayOfWeek.of(1).toString());
Output:
MONDAY
Answer found thanks to shmosel. I am using the following :
DateFormatSymbols.getInstance().getWeekdays()
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With