java.util.Calendar DAY_OF_WEEK_IN_MONTH
中文JDK说明: --------------------------------------------------- public static final int DAY_OF_WEEK_IN_MONTH
get 和 set 的字段数字,指示当前月中的第几个星期。与 DAY_OF_WEEK 字段一起使用时,就可以惟一地指定某月中的某一天。
与 WEEK_OF_MONTH 和 WEEK_OF_YEAR 不同,该字段的值并不 取决于 getFirstDayOfWeek() 或 getMinimalDaysInFirstWeek()。
DAY_OF_MONTH 1 到 7 总是对应于 DAY_OF_WEEK_IN_MONTH 1;8 到 14 总是对应于 DAY_OF_WEEK_IN_MONTH 2,依此类推。
DAY_OF_WEEK_IN_MONTH 0 表示 DAY_OF_WEEK_IN_MONTH 1 之前的那个星期。
负值是从一个月的末尾开始反向计数,因此,一个月的最后一个星期天被指定为 DAY_OF_WEEK = SUNDAY, DAY_OF_WEEK_IN_MONTH = -1。
因为负值是反向计数的,所以它们在月份中的对齐方式通常与正值的不同。例如,如果一个月有 31 天,那么 DAY_OF_WEEK_IN_MONTH -1 将与 DAY_OF_WEEK_IN_MONTH 5 和 DAY_OF_WEEK_IN_MONTH 4 的末尾相重叠。 ----------------------------------------------------------
英文JDK说明: ---------------------------------------------------------- public static final int DAY_OF_WEEK_IN_MONTH
Field number for get and set indicating the ordinal number of the day of the week within the current month. Together with the DAY_OF_WEEK field, this uniquely specifies a day within a month.
Unlike WEEK_OF_MONTH and WEEK_OF_YEAR, this field's value does not depend on getFirstDayOfWeek() or getMinimalDaysInFirstWeek().
DAY_OF_MONTH 1 through 7 always correspond to DAY_OF_WEEK_IN_MONTH 1; 8 through 14 correspond to DAY_OF_WEEK_IN_MONTH 2, and so on.
DAY_OF_WEEK_IN_MONTH 0 indicates the week before DAY_OF_WEEK_IN_MONTH 1. Negative values count back from the end of the month, so the last Sunday of a month is specified as DAY_OF_WEEK = SUNDAY, DAY_OF_WEEK_IN_MONTH = -1.
Because negative values count backward they will usually be aligned differently within the month than positive values. For example, if a month has 31 days, DAY_OF_WEEK_IN_MONTH -1 will overlap DAY_OF_WEEK_IN_MONTH 5 and the end of 4. -------------------------------------------------------------
看着解释有点晕,后来才搞明白, DAY_OF_WEEK_IN_MONTH 就是指示当前这个日期是这个月的第几个星期几。 比如2006/06/26是6月的第四个星期一,恩,对了,DAY_OF_WEEK_IN_MONTH返回4。 2006/06/01是6月的第一个星期四,DAY_OF_WEEK_IN_MONTH返回1。
明白了吧,千万不要理解为本月的第几周,那个应该是WEEK_OF_MONTH。 比如2006/06/26,WEEK_OF_MONTH返回5。 2006/06/01,WEEK_OF_MONTH返回1。
还有,开始挺纳闷为什么DAY_OF_WEEK_IN_MONTH对1-7号都返回1,8-14号都返回2,15-21号都返回3....
后来一想,可不就是这么简单嘛,
1-7号一定把星期一到星期日都占全了,所以不管是哪天,都是本月的第一个星期N。 8-14号,一样,不管是哪天,前面1-7号一定有一个星期N了,那么它就是第二个星期N。 同理......
|