例如: 给定月份 = 2,给定年份 = 2014,我使用以下代码获得了周列表。为什么我一个月申请 1 是默认月份仅以索引开头。
示例代码:
Calendar calendar = Calendar.getInstance();
calendar.set(1, 2014);
calendar.set(2014, 1, 1);
int ndays = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
Set<Integer> weeks = new HashSet<Integer>();
for (int i = 1; i <= ndays; i++) {
weeks.add(calendar.get(Calendar.WEEK_OF_YEAR));
calendar.add(Calendar.DATE, 1);
}
结果: 周 => [8, 9, 5, 6, 7]
获得此结果后,我如何才能获得一年中可用的日期。2014 年 2 月,第 5 周只有一天(星期六)。除最后 9 周外,其余周有 7 天。
我期望的格式:
week5 => 1-saturday
week6 => 2-sunday
3-monday
4-tuesday
5-wednesday
6-thursday
7-friday
8-saturday
week7 => 9-sunday
.
.
.
.
week9 => 23-sunday
24-monday
25-tuesday
26-wednesday
27-thursday
28-friday
29-saturday
有人指导我得到这个 List< Key,datelist > 对,如上面的结果。