Java之~根据指定时间,获取时间list,1天

/**
 * 根据时间获取时间段list
 * @param startTime
 * @param endTime
 * @return
 */
@NotNull
private List getDays(Date startTime,Date endTime) {
    List days = new ArrayList();
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

    Date start = startTime;
    Date end = endTime;
    Calendar tempStart = Calendar.getInstance();
    tempStart.setTime(start);
    Calendar tempEnd = Calendar.getInstance();
    tempEnd.setTime(end);
    tempEnd.add(Calendar.DATE, +1);
    while (tempStart.before(tempEnd)) {
        days.add(dateFormat.format(tempStart.getTime()));
        tempStart.add(Calendar.DAY_OF_YEAR, 1);
    }
    return days;
}

你可能感兴趣的:(Java,java,开发语言)