Android Calendar get current day of week as string

ntm picture ntm · Aug 15, 2013 · Viewed 80.3k times · Source

i tried to get a string with the name of the actual weekday this way:

            Calendar c = Calendar.getInstance();
            int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);

            if (c.get(Calendar.MONDAY) == dayOfWeek) weekDay = "monday";
            else if (c.get(Calendar.TUESDAY) == dayOfWeek) weekDay = "tuesday";
            else if (c.get(Calendar.WEDNESDAY) == dayOfWeek) weekDay = "wednesday";
            else if (c.get(Calendar.THURSDAY) == dayOfWeek) weekDay = "thursday";
            else if (c.get(Calendar.FRIDAY) == dayOfWeek) weekDay = "friday";
            else if (c.get(Calendar.SATURDAY) == dayOfWeek) weekDay = "saturday";
            else if (c.get(Calendar.SUNDAY) == dayOfWeek) weekDay = "sunday";

but weekDay stays always null and i actually have no idea why because the debugger says that dayOfWeek is 5 so i should be equal to c.get(Calendar.THURSDAY)

Answer

sandalone picture sandalone · Apr 24, 2014

As simple as this

sCalendar = Calendar.getInstance();
String dayLongName = sCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault());