//时间处理
public List<String> completionDate(List<String> list ,Date begin , int daySub){
ArrayList<String> dateResult = new ArrayList<String>();
//时间增加一天
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar yesterday = Calendar.getInstance();
yesterday.add(Calendar.DAY_OF_MONTH, 1);
//字符串转化为时间
Calendar calendar10 = Calendar.getInstance();
Calendar calendar5 = Calendar.getInstance();
calendar10.setTime(begin);
for(int curr = 0 ; curr < daySub ; curr++){
boolean dbDataExist = false;
int index = 0;
for(int i = 0 ; i < list.size() ; i++){
try {
Date date2 = sdf.parse(list.get(i));
calendar5.setTime(date2);
} catch (ParseException e) {
e.printStackTrace();
}
if(calendar10.compareTo(calendar5) == 0){
dbDataExist = true;
index = i;
break;
}
}
if(dbDataExist){
dateResult.add(list.get(index));
}else{
dateResult.add(sdf.format(calendar10.getTime()));
}
//还原calendar10
calendar10.add(Calendar.DAY_OF_MONTH, 1 );
}
return dateResult;
}
日常积累-时间段内不存在天数补全工具类(格式:yyyy-mm-dd)
最新推荐文章于 2019-09-04 22:24:50 发布