输入开始时间和结束时间,获取时间列表

 /* 获得时间列表
     * @param startDate
     * @param endDate
     * @return
     * @throws Exception
     */
    public List<Date> getDateList(Date startDate, Date endDate)throws Exception{
        List<Date> dateList = new ArrayList<Date>();
        if(startDate!=null&&endDate!=null&&!endDate.before(startDate)){
                dateList.add(startDate);
                while(startDate.before(endDate)){
                    Calendar calendar = Calendar.getInstance();
                    calendar.setTime(startDate);
                    calendar.add(calendar.DATE, 1);
                    startDate = calendar.getTime();
                    dateList.add(startDate);
                }
            return dateList;
        }
        return null;
    }

 

posted @ 2014-11-18 15:26  盛夏微风  阅读(479)  评论(0编辑  收藏  举报