1

I'm confused about how a Gregorian Calendar associates days with numbers. For examples, I instantiate an object

GregorianCalendar cal = new GregorianCalendar();
Toast.makeText(context, "Day: " + cal.DAY_OF_WEEK, Toast.LENGTH_LONG).show();

My toast messages keeps dispalying "Day: 7"

Today is Friday, assuming that Sunday = 0, shouldn't the text display "Day: 5"?

It does work when I do the following:

int current day = cal.get(Calendar.DAY_OF_WEEK)

Can someone explain why? Thank you.

Mark F
  • 1,523
  • 3
  • 23
  • 41

1 Answers1

1

The reason that you're getting a 7 with cal.DAY_OF_WEEK, is that you're actually asking for the value of the constant named DAY_OF_WEEK and the value of that field is 7. See here. In other words, cal.DAY_OF_WEEK is really equivalent to Calendar.DAY_OF_WEEK.

You get the correct answer with cal.get(Calendar.DAY_OF_WEEK), because you're then asking for the value of cal's DAY_OF_WEEK field.

scottt
  • 8,301
  • 1
  • 31
  • 41