yanghui
2022-11-28 42521c9b51c1bd9a40036f18fd610cd46601222d
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/DateUtils.java
@@ -926,11 +926,11 @@
    }
    public static void main(String[] args) throws Exception {
         Date date= getLastMonthFirst();
         Date after = getLastMonthEnd();
         System.out.println(date);
         System.out.println(after);
         System.out.println(getMonthTwentyDay());
//        List<String> beforeDays = getBeforeDays(15);
//        System.out.println(beforeDays);
        List<String> yearMonths = getYearMonths();
        System.out.println(yearMonths);
    }
    /**
@@ -1142,6 +1142,18 @@
    }
    /**
     * 获取之前的日期
     *
     * @return
     */
    public static String getBeforeDay(Integer amount) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        cal.add(Calendar.DATE, -amount);
        return DateUtil.format(cal.getTime(),"yyyy-MM-dd");
    }
    /**
     * 获取最近本月20天数据
     *
     * @return
@@ -1162,4 +1174,33 @@
        }
    }
    public static List<String> getBeforeDays(int before) {
        List<String> dates = new ArrayList<>();
        for (int i = before; i >= 0; i--) {
            dates.add(getBeforeDay(i));
        }
        return dates;
    }
    /**
     * 获取当年所有月份
     *
     * @return
     */
    public static List<String> getYearMonths() {
        Calendar instance = Calendar.getInstance();
        int year = instance.get(Calendar.YEAR);
        List<String> months = new ArrayList<>();
        for (int i = 1; i <= 12; i++) {
            String result = String.valueOf(year);
            if (i < 10) {
                result = result + "-0" +i;
            } else {
                result = result + "-"+i;
            }
            months.add(result);
        }
        return months;
    }
}