/**
* 得到两个日期之间的 日期字符串集合[2022-03-22, 2022-03-23]
* @param startTime 开始的时间
* @param endTime 结束的时间
* @return
*/
public static List<String> getBetweenDays(String startTime, String endTime) throws ParseException {
if (org.thymeleaf.util.StringUtils.isEmpty(startTime) || org.thymeleaf.util.StringUtils.isEmpty(endTime)) {
return null;
}
//1、定义转换格式
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date start = df.parse(startTime);
Date end = df.parse(endTime);
if (start==null || end==null ) {
return null;
}
List<String> result = new ArrayList<String>();
Calendar tempStart = Calendar.getInstance();
tempStart.setTime(start);
tempStart.add(Calendar.DAY_OF_YEAR, 1);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar tempEnd = Calendar.getInstance();
tempEnd.setTime(end);
result.add(sdf.format(start));
while (tempStart.before(tempEnd)) {
result.add(sdf.format(tempStart.getTime()));
tempStart.add(Calendar.DAY_OF_YEAR, 1);
}
return result;
}
得到两个日期之间的日期字符串集合
最新推荐文章于 2023-06-17 11:45:29 发布
关键词由CSDN通过智能技术生成