/**
* 从大到小
*/
public List<LocalDate> getDescDateList(LocalDate startDate,LocalDate endDate) {
long size = endDate.toEpochDay() - startDate.toEpochDay();
if (size < 0) {
return Collections.emptyList();
}
// 初始化大小防止list频繁扩容
List<LocalDate> result = new ArrayList<>((int)size);
for (int i = 0; i < size ; i ++) {
result.add(endDate);
endDate = endDate.plusDays(-1);
}
return result;
}
/**
* 从小到大
*/
public List<LocalDate> getAscDateList(LocalDate startDate,LocalDate endDate) {
long size = endDate.toEpochDay() - startDate.toEpochDay();
if (size < 0) {
return Collections.emptyList();
}
// 初始化大小防止list频繁扩容
List<LocalDate> result = new ArrayList<>((int)size);
for (int i = 0; i < size ; i ++) {
result.add(startDate);
startDate = startDate.plusDays(1);
}
return result;
}
获取俩个LocalDate中间所有的日期
于 2019-09-04 10:54:50 首次发布
本文介绍了一个实用的日期范围生成算法,能够根据起始和结束日期,生成从小到大或从大到小的日期列表,适用于各种需要连续日期数据的场景。
开发板推荐:天空星STM32F407VET6开发板
超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印
开发板推荐:天空星STM32F407VET6开发板
超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印

3653

被折叠的 条评论
为什么被折叠?



