java 如何实现两个对两个日期之间所有日期的遍历

2024-11-19 04:18:45
推荐回答(1个)
回答1:

参考下面代码:
public static void main(String[] args) {

Calendar start = Calendar.getInstance();
start.set(2014, 6, 11);
Long startTIme = start.getTimeInMillis();

Calendar end = Calendar.getInstance();
end.set(2014, 7, 11);
Long endTime = end.getTimeInMillis();

Long oneDay = 1000 * 60 * 60 * 24l;

Long time = startTIme;
while (time <= endTime) {
Date d = new Date(time);
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
System.out.println(df.format(d));
time += oneDay;
}
}