Search code examples
androidcalendardayofweek

GregorianCalendar DayofWeek


I know this has to be out there somewhere, but how does the GregorianCalendar class determine which day is the first day of the week? Does it do this by Locale, or does it remain static?

What I'm ultimately trying to do is test to determine whether it is the weekend in the United States. Any pointers?


Solution

  • GregorianCalendar determines it by Locale.

    You could do something like.

    GregorianCalendar cal = new GregorianCalendar(someTimezone, Locale.US);
    int day = cal.get(Calendar.DAY_OF_WEEK);
    if (day == Calendar.SATURDAY || day == Calendar.SUNDAY) {
    // do something interesting
    }