Java 通過日曆類根據傳入的年份 月分及開始日期 計算 傳入月份還剩哪些天

  /**
     * author ;sfy
     * 根據傳入的 年份 月分, 及開始 日期
     * 計算 傳入月份還剩 哪些天
     *
     * @param year
     * @param month
     * @param today
     * @return
     */
    public static List<String> getAllDayByMonth(int year, int month, int today) {
        SimpleDateFormat dateFormatYYYYMMDD = new SimpleDateFormat("MM月dd日");
        List<String> fullDayList = new ArrayList<>(32);
        // 獲得當前日期對象
        Calendar cal = Calendar.getInstance();
        cal.clear();// 清除信息
        cal.set(Calendar.YEAR, year);
        // 1月從0開始
        cal.set(Calendar.MONTH, month - 1);
        // 當月當前天
        cal.set(Calendar.DAY_OF_MONTH, today);
        int count = 0;
        count = cal.getActualMaximum(Calendar.DAY_OF_MONTH) - today + 1;


        for (int j = 1; j <= count; j++) {
            fullDayList.add(dateFormatYYYYMMDD.format(cal.getTime()));
            cal.add(Calendar.DAY_OF_MONTH, 1);
        }

        return fullDayList;
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章