jinpengyong
2021-08-04 765460125202c993f737dee3a05d54c66ade2499
screen-common/src/main/java/com/moral/util/DateUtils.java
@@ -1355,4 +1355,37 @@
        }
        return date;
    }
    /*
    * 根据时间获取时间内时间点
    * 例:time=2021-08-04 就得到这天内每个小时时间点
    *    time=2021-08 就得到这月内每天时间点
    * */
    public static List<String> getTimeLag(String time) {
        List<String> result = new ArrayList<>();
        int length = time.length();
        Calendar cal = Calendar.getInstance();
        String end;
        String dateFormat;
        int i;
        if (length == 10) {//日
            end = getDateAddDay(time, 1);
            dateFormat = yyyy_MM_dd_EN;
            i = Calendar.HOUR_OF_DAY;
        } else if (length == 7) {//月
            end = getDateAddMonth(time, 1);
            dateFormat = yyyy_MM_EN;
            i = Calendar.DAY_OF_MONTH;
        } else {//年
            end = getDateAddYear(time, 1);
            dateFormat =yyyy;
            i = Calendar.MONTH;
        }
        cal.setTime(getDate(time, dateFormat));
        for (long d = cal.getTimeInMillis(); d < getDate(end, dateFormat).getTime(); cal.set(i, cal.get(i) + 1), d = cal.getTimeInMillis()) {
            String format = dateToDateString(new Date(d));
            result.add(format);
        }
        return result;
    }
}