当前位置: 技术问答>java相关
有没有什么方法,可以直接得到一个月的第一个星期日是几号???谢谢
来源: 互联网 发布时间:2015-09-29
本文导语: 得到一个月的1号是星期几,再慢慢推, 这个方法好象慢了点。 java中有直接的方法么??? 或者谁还有更快的方法??? | Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_WEEK...
得到一个月的1号是星期几,再慢慢推, 这个方法好象慢了点。
java中有直接的方法么???
或者谁还有更快的方法???
java中有直接的方法么???
或者谁还有更快的方法???
|
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_WEEK,Calendar.SUNDAY);//取星期天
cal.set(Calendar.DAY_OF_WEEK_IN_MONTH,1);//取第一个
System.out.println(cal.getTime());
cal.set(Calendar.DAY_OF_WEEK,Calendar.SUNDAY);//取星期天
cal.set(Calendar.DAY_OF_WEEK_IN_MONTH,1);//取第一个
System.out.println(cal.getTime());
|
DAY_OF_WEEK_IN_MONTH
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.
See Also:
DAY_OF_WEEK, WEEK_OF_MONTH, Constant Field Values
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.
See Also:
DAY_OF_WEEK, WEEK_OF_MONTH, Constant Field Values
|
有个函数直接可以得到
new Data()
在java.util中
new Data()
在java.util中
|
我觉得如果有万年历的代码的话做这个就很容易了,自己写一个类吗,管他复杂与否,解决问题先呀,经验的积累自然就会有更好的方法
|
关注