简体   繁体   English

Calendar.get(Calendar.DAY_OF_WEEK)是否受Calendar.getFirstDayOfWeek()影响?

[英]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. 也许是一个愚蠢的问题,但是我有一个Java文档中没有发现的问题。

Does the value of Calendar.get(Calendar.DAY_OF_WEEK) change based on any value change of Calendar.getFirstDayOfWeek() ? Calendar.get(Calendar.DAY_OF_WEEK)的值是否会基于Calendar.getFirstDayOfWeek()任何值更改而改变?

Or does Calendar.get(Calendar.DAY_OF_WEEK) always give the correct answer (based on the current locale)? 还是Calendar.get(Calendar.DAY_OF_WEEK)总是给出正确答案(基于当前语言环境)?

Does the value of Calendar.get(Calendar.DAY_OF_WEEK) change based on any value change of Calendar.getFirstDayOfWeek() Calendar.get(Calendar.DAY_OF_WEEK)的值是否基于Calendar.getFirstDayOfWeek()任何值更改而改变

No. Sunday is Sunday ( Calendar.SUNDAY ), regardless of whether that's the first day of the week, the second or the seventh. 否。星期日是星期天( Calendar.SUNDAY ),而不管是一周的第一天,第二天还是第七天。 (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) . Calendar.getFirstDayOfWeek()不会影响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. 它可能会影响Calendar.WEEK_OF_YEAR因为在计算当前星期数时会考虑一周的第一天。

The documentation of the DAY_OF_WEEK constant actually says: DAY_OF_WEEK常量的文档实际上说:

Field number for get and set indicating the day of the week. get和set的字段号指示星期几。 This field takes values SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, and SATURDAY. 此字段采用值SUNDAY,MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY和SATURDAY。

This means that the values returned from get for this constant are not interpreted as ordinal numbers. 这意味着从get返回的该常量值不会解释为序数。 These are all (static) constants in the Calendar class. 这些都是Calendar类中的所有(静态)常量。 The fact that they evaluate to 1,2,3 shouldn't confuse you. 他们评估为1,2,3的事实不应使您感到困惑。 They mean "Sunday, Monday, Tuesday", not "First day, second day, third day". 它们的意思是“星期日,星期一,星期二”,而不是“第一天,第二天,第三天”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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