java 通过开始结束时间,得到中间的所有时间

private static List<Date> getBetweenDates(Date start,Date end){
    List<Date> result = new ArrayList<Date>();
    Calendar tempStart = Calendar.getInstance();
    tempStart.setTime(start);
    tempStart.add(Calendar.DAY_OF_YEAR, 1);
    
    Calendar tempEnd = Calendar.getInstance();
    tempEnd.setTime(end);
    while (tempStart.before(tempEnd)) {
        result.add(tempStart.getTime());
        tempStart.add(Calendar.DAY_OF_YEAR, 1);
    }
    return result;

}


发布了31 篇原创文章 · 获赞 24 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/hengliang_/article/details/80109003
今日推荐