您的位置:首页 > 其它

计算两个日期之间的周

2015-10-13 13:54 253 查看
public void getDays() {

Calendar c_begin = new GregorianCalendar();
Calendar c_end = new GregorianCalendar();
DateFormatSymbols dfs = new DateFormatSymbols();
String[] weeks = dfs.getWeekdays();

c_begin.set(2015, 8, 2); // Calendar的月从0-11,所以4月是3.
c_end.set(2015, 9, 20); // Calendar的月从0-11,所以5月是4.

int count = 1;
c_end.add(Calendar.DAY_OF_YEAR, 1); // 结束日期下滚一天是为了包含最后一天

while (c_begin.before(c_end)) {
System.out.println("第" + count + "周 日期:"
+ new Date(c_begin.getTime().getTime()) + ","
+ weeks[c_begin.get(Calendar.DAY_OF_WEEK)]);

if (c_begin.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
count++;
}
c_begin.add(Calendar.DAY_OF_YEAR, 1);
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: