Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get day string from day of week integer java [duplicate]

Tags:

java

date

android

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 ?

like image 706
Alex R. Avatar asked Aug 17 '16 07:08

Alex R.


3 Answers

You can use the DayOfWeek enum to get a day by its number:

System.out.println(DayOfWeek.of(1).toString());

Output:

MONDAY
like image 79
shmosel Avatar answered Oct 13 '22 01:10

shmosel


Answer found thanks to shmosel. I am using the following :

DateFormatSymbols.ge‌tInstance().getWeekda‌​ys()
like image 23
Alex R. Avatar answered Oct 13 '22 01:10

Alex R.


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
like image 30
Rinku Jagdale Avatar answered Oct 13 '22 02:10

Rinku Jagdale