SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date dBegin = sdf.parse("2018-01-01");
Date dEnd = sdf.parse("2019-01-01");
List<String> datas = findDates(dBegin, dEnd);
public List<String> findDates(Date dBegin, Date dEnd){
List<String> lDate = new ArrayList<String>();
SimpleDateFormat sd = new SimpleDateFormat("yyyyMMdd hh:mm:ss");
lDate.add(sd.format(dBegin));
Calendar calBegin = Calendar.getInstance();
// 使用給定的 Date 設置此 Calendar 的時間
calBegin.setTime(dBegin);
Calendar calEnd = Calendar.getInstance();
// 使用給定的 Date 設置此 Calendar 的時間
calEnd.setTime(dEnd);
// 測試此日期是否在指定日期之后
while (dEnd.after(calBegin.getTime()))
{
// 根據日歷的規則,為給定的日歷字段添加或減去指定的時間量
calBegin.add(Calendar.DAY_OF_MONTH, 1);
lDate.add(sd.format(calBegin.getTime()));
}
return lDate;
}
