获取当月所有日期

    public static List<Date> getDayListOfMonth() throws ParseException {
        List list = new ArrayList();
        Calendar aCalendar = Calendar.getInstance(Locale.CHINA);
        int year = aCalendar.get(Calendar.YEAR);//年份
        int month = aCalendar.get(Calendar.MONTH) + 1;//月份
        int day = aCalendar.getActualMaximum(Calendar.DATE);
        String monthStr="0";
        if(month<10){
            monthStr="0"+month;
        }else{
            monthStr=String.valueOf(month);
        }
        for (int i = 1; i <= day; i++) {
            String days= "0";
            if(i<10){
                days="0"+i;
            }else {
                days=String.valueOf(i);
            }
            String aDate = String.valueOf(year)+"-"+monthStr+"-"+days;
            SimpleDateFormat sp=new SimpleDateFormat("yyyy-MM-dd");
            Date date = sp.parse(aDate);
            list.add(sp.format(date));
        }
        return list;
    }

 

posted @ 2022-05-28 10:04  _Lawrence  阅读(416)  评论(0编辑  收藏  举报