如何在java中获得两个日期之间的日期列表我要从开始日期到结束日期之间的日期列表。结果应该是所有日期的列表,包括开始日期和结束日期。
3 回答

慕尼黑5688855
TA贡献1848条经验 获得超2个赞
早在2010年,我就建议用 尤达-时间 为了这个。
注意,Joda-Time现在处于维护模式。从1.8(2014)开始,您应该使用 java.time
.
int days = Days.daysBetween(startDate, endDate).getDays();List<LocalDate> dates = new ArrayList<LocalDate>(days); // Set initial capacity to `days`.for (int i=0; i < days; i++) { LocalDate d = startDate.withFieldAdded(DurationFieldType.days(), i); dates.add(d);}

精慕HU
TA贡献1845条经验 获得超8个赞
java.time包
String s = "2014-05-01";String e = "2014-05-10";LocalDate start = LocalDate.parse(s); LocalDate end = LocalDate.parse(e);List<LocalDate> totalDates = new ArrayList<>(); while (!start.isAfter(end)) { totalDates.add(start); start = start.plusDays(1);}
添加回答
举报
0/150
提交
取消