简体   繁体   中英

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)?

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.)

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.

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".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM