[心缘地方]同学录
首页 | 功能说明 | 站长通知 | 最近更新 | 编码查看转换 | 代码下载 | 常见问题及讨论 | 《深入解析ASP核心技术》 | 王小鸭自动发工资条VBA版
登录系统:用户名: 密码: 如果要讨论问题,请先注册。

[java]java.util.Calendar的属性DAY_OF_WEEK_IN_MONTH

上一篇:[java]用于较小数的 BigDecimal
下一篇:[java]如何遍历Properties的所有的元素-----Listing the Elements of a Properties

添加日期:2006/6/26 17:29:36 快速返回   返回列表 阅读12840次
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。
同理......
 

评论 COMMENTS
sui-feng
2007/11/22 14:28:26
good
guest108754386
2012/10/7 10:16:44
非常感谢啊。。。
guest370466994
2014/4/14 14:38:49
Thanks

添加评论 Add new comment.
昵称 Name:
评论内容 Comment:
验证码(不区分大小写)
Validation Code:
(not case sensitive)
看不清?点这里换一张!(Change it here!)
 
评论由管理员查看后才能显示。the comment will be showed after it is checked by admin.
CopyRight © 心缘地方 2005-2999. All Rights Reserved