Util工具类 获取某日期区间的所有日期

来源:互联网 发布:工业大数据 李杰 下载 编辑:程序博客网 时间:2024/05/17 04:05
/** * 获取某日期区间的所有日期  日期倒序 * * @param startDate  开始日期 * @param endDate    结束日期 * @param dateFormat 日期格式 * @return 区间内所有日期 */public static List<String> getPerDaysByStartAndEndDate(String startDate, String endDate, String dateFormat) {    DateFormat format = new SimpleDateFormat(dateFormat);    try {        Date sDate = format.parse(startDate);        Date eDate = format.parse(endDate);        long start = sDate.getTime();        long end = eDate.getTime();        if (start > end) {            return null;        }        Calendar calendar = Calendar.getInstance();        calendar.setTime(eDate);        List<String> res = new ArrayList<String>();        while (end >= start) {            res.add(format.format(calendar.getTime()));            calendar.add(Calendar.DAY_OF_MONTH, -1);            end = calendar.getTimeInMillis();        }        return res;    } catch (ParseException e) {        logger.error(e.getMessage(), e);    }    return null;}


更多工具类方法:http://blog.csdn.net/qq_34117825/article/details/78392976

阅读全文
1 0
原创粉丝点击