corgrath
corgrath

Reputation: 12293

Is Calendar.get(Calendar.DAY_OF_WEEK) impacted by Calendar.getFirstDayOfWeek()?

Maybe a stupid question, but I have a question I didn't find in the Java documentation.

Does the value of Calendar.get(Calendar.DAY_OF_WEEK) change based on any value change of Calendar.getFirstDayOfWeek()?

Or does Calendar.get(Calendar.DAY_OF_WEEK) always give the correct answer (based on the current locale)?

Upvotes: 1

Views: 293

Answers (3)

Jon Skeet
Jon Skeet

Reputation: 1503419

Does the value of Calendar.get(Calendar.DAY_OF_WEEK) change based on any value change of Calendar.getFirstDayOfWeek()

No. Sunday is Sunday (Calendar.SUNDAY), regardless of whether that's the first day of the week, the second or the seventh. (If you're using a non-Gregorian calendar which may have entirely different week days, that's a different matter of course.)

Upvotes: 1

RealSkeptic
RealSkeptic

Reputation: 34638

The documentation of the DAY_OF_WEEK constant actually says:

Field number for get and set indicating the day of the week. This field takes values SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, and SATURDAY.

This means that the values returned from get for this constant are not interpreted as ordinal numbers. These are all (static) constants in the Calendar class. The fact that they evaluate to 1,2,3 shouldn't confuse you. They mean "Sunday, Monday, Tuesday", not "First day, second day, third day".

Upvotes: 0

M A
M A

Reputation: 72884

Calendar.getFirstDayOfWeek() does not affect the value of Calendar.get(Calendar.DAY_OF_WEEK). What it affects is probably Calendar.WEEK_OF_YEAR because the first day of the week is considered when calculating the current week number.

Upvotes: 1

Related Questions