Java Day of Week getDaysByWeek2(Integer month, Integer year, Integer begin)

Here you can find the source of getDaysByWeek2(Integer month, Integer year, Integer begin)

Description

get Days By Week

License

Open Source License

Declaration

public static Map<Integer, Integer> getDaysByWeek2(Integer month, Integer year, Integer begin) 

Method Source Code

//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;
    }
}

Related

  1. getDayOfWeek(String format, int calendarField)
  2. getDayOfWeekAsString(String sYear, String sMonth, String sDay)
  3. getDayofWeekByDay(String year, String month, String day)
  4. getDayofWeekForContainedDate(Date dt, DayOfWeek dow)
  5. getDaysByWeek(Integer month, Integer year, Integer week)
  6. getDayWeekDate(String dateStr)
  7. getDayWeekDateStr(Date date)
  8. getEndOfWeek(Date date)
  9. getFirstDayOfLastWeek(Date date)