获取指定时间内的所有时间

来源:互联网 发布:qt编程语言 编辑:程序博客网 时间:2024/05/21 18:30
    public String[] getHotelDate(String startdate, String enddate) {        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");        try {            Date d1 = f.parse(startdate);            Date d2 = f.parse(enddate);            long days = (d2.getTime() - d1.getTime()) / 3600000 / 24;            Calendar startcal = Calendar.getInstance();            Calendar endcal = Calendar.getInstance();            startcal.setTime(d1);            endcal.setTime(d2);            String hotelDate[] = new String[(int) days + 1];            hotelDate[0] = f.format(d1);            int i = 1;            while (endcal.after(startcal)) {                if (i <= days)                    startcal.add(Calendar.DATE, 1);                hotelDate[i] = f.format(startcal.getTime());                i++;            }            return hotelDate;        } catch (ParseException e) {            e.printStackTrace();        }        return null;    }