Here you can find the source of getDaysByWeek2(Integer month, Integer year, Integer begin)
public static Map<Integer, Integer> getDaysByWeek2(Integer month, Integer year, Integer begin)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; import java.util.HashMap; import java.util.Map; public class Main { public static Map<Integer, Integer> getDaysByWeek2(Integer month, Integer year, Integer begin) { Map<Integer, Integer> map = new HashMap<Integer, Integer>(); Calendar c = Calendar.getInstance(); c.set(year, month - 1, 1);//w w w . j a va 2s . com for (int i = 1; i < begin; i++) { c.set(Calendar.DAY_OF_MONTH, i); if (1 == c.get(Calendar.DAY_OF_WEEK)) { Integer value = map.get(1) == null ? 0 : map.get(1); map.put(1, value + 1); } if (2 == c.get(Calendar.DAY_OF_WEEK)) { Integer value = map.get(2) == null ? 0 : map.get(2); map.put(2, value + 1); } if (3 == c.get(Calendar.DAY_OF_WEEK)) { Integer value = map.get(3) == null ? 0 : map.get(3); map.put(3, value + 1); } if (4 == c.get(Calendar.DAY_OF_WEEK)) { Integer value = map.get(4) == null ? 0 : map.get(4); map.put(4, value + 1); } if (5 == c.get(Calendar.DAY_OF_WEEK)) { Integer value = map.get(5) == null ? 0 : map.get(5); map.put(5, value + 1); } if (6 == c.get(Calendar.DAY_OF_WEEK)) { Integer value = map.get(6) == null ? 0 : map.get(6); map.put(6, value + 1); } if (7 == c.get(Calendar.DAY_OF_WEEK)) { Integer value = map.get(7) == null ? 0 : map.get(7); map.put(7, value + 1); } } return map; } }