What would be the easiest way to get the current day of the week in Android?
If you do not want to use Calendar class at all you can use this
String weekday_name = new SimpleDateFormat("EEEE", Locale.ENGLISH).format(System.currentTimeMillis());
i.e., result is,
"Sunday"
Java 8 datetime
API
made it so much easier :
LocalDate.now().getDayOfWeek().name()
Will return you the name of the day as String
Output : THURSDAY
Calendar.getInstance().get(Calendar.DAY_OF_WEEK)
or
new GregorianCalendar().get(Calendar.DAY_OF_WEEK);
Just the same as in Java, nothing particular to Android.
Here is my simple approach to get Current day
public String getCurrentDay(){
String daysArray[] = {"Sunday","Monday","Tuesday", "Wednesday","Thursday","Friday", "Saturday"};
Calendar calendar = Calendar.getInstance();
int day = calendar.get(Calendar.DAY_OF_WEEK);
return daysArray[day];
}
As DAY_OF_WEEK in GregorianCalender class is a static field you can access it directly as foolows
int dayOfWeek = GregorianCalender.DAY_OF_WEEK;