Java Day of Week getDaysByWeek(Integer month, Integer year, Integer week)

Here you can find the source of getDaysByWeek(Integer month, Integer year, Integer week)

Description

get Days By Week

License

Open Source License

Declaration


public static Integer getDaysByWeek(Integer month, Integer year, Integer week) 

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 Integer getDaysByWeek(Integer month, Integer year, Integer week) {
        Integer num = null;/*w  ww  .  ja v a2 s  .c om*/
        Calendar c = Calendar.getInstance();
        c.set(year, month - 1, 1);
        int mountDay = c.getActualMaximum(Calendar.DAY_OF_MONTH);
        num = mountDay / 7;
        int yu = mountDay % 7;
        for (int i = 1; i <= yu; i++) {
            c.set(Calendar.DAY_OF_MONTH, i);
            if (week == c.get(Calendar.DAY_OF_WEEK)) {
                num++;
                break;
            }
        }
        return num;
    }

    public static Map<Integer, Integer> getDaysByWeek(Integer month, Integer year) {
        Map<Integer, Integer> map = new HashMap<Integer, Integer>();
        Integer num = null;
        Calendar c = Calendar.getInstance();
        c.set(year, month - 1, 1);
        int mountDay = c.getActualMaximum(Calendar.DAY_OF_MONTH);
        num = mountDay / 7;
        int yu = mountDay % 7;
        for (int j = 1; j <= 7; j++) {
            for (int i = 1; i <= yu; i++) {
                c.set(Calendar.DAY_OF_MONTH, i);
                map.put(j, num);
                if (j == c.get(Calendar.DAY_OF_WEEK)) {
                    map.put(j, num + 1);
                    break;
                }
            }
        }
        return map;
    }
}

Related

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