我有一个日期数组,其中包含从今天起的15天。我想验证丢失的日期并尝试打印它…
我正在为前端chartjs条形图构建一个API。我正在尝试获取从今天起15天的记录计数。如果没有特定日期的记录或某些日期丢失,我将在该记录中添加0。我正在试图打印丢失的日期
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
public class Dummy {
public static void main(String args[]) {
LocalDate Today = LocalDate.now();
LocalDate checkDate = Today.minusDays(14);
List<String> apiObj = new ArrayList<>();
apiObj.add("2020-12-10");
apiObj.add("2020-12-11");
apiObj.add("2020-12-12");
apiObj.add("2020-12-13");
apiObj.add("2020-12-14");
// apiObj.add("2020-12-15");
apiObj.add("2020-12-16");
apiObj.add("2020-12-17");
apiObj.add("2020-12-18");
apiObj.add("2020-12-19");
apiObj.add("2020-12-20");
apiObj.add("2020-12-21");
apiObj.add("2020-12-22");
apiObj.add("2020-12-23");
apiObj.add("2020-12-24");
for (int i = 0; i < apiObj.size(); i++) {
System.out.println("API DATA : " + apiObj.get(i) + " Check Date : " + checkDate);
System.out.println("Logic Check : " + checkDate.toString().equals(apiObj.get(i)));
if (!checkDate.toString().equals(apiObj.get(i))) {
System.out.println("Missing Date " + checkDate);
}
checkDate = checkDate.plusDays(1);
}
}
}
评论日期后所有事情都会出错
我得到的输出
API DATA : 2020-12-10 Check Date : 2020-12-10
Logic Check : true
API DATA : 2020-12-11 Check Date : 2020-12-11
Logic Check : true
API DATA : 2020-12-12 Check Date : 2020-12-12
Logic Check : true
API DATA : 2020-12-13 Check Date : 2020-12-13
Logic Check : true
API DATA : 2020-12-14 Check Date : 2020-12-14
Logic Check : true
API DATA : 2020-12-16 Check Date : 2020-12-15
Logic Check : false
Missing Date 2020-12-15
API DATA : 2020-12-17 Check Date : 2020-12-16
Logic Check : false
Missing Date 2020-12-16
API DATA : 2020-12-18 Check Date : 2020-12-17
Logic Check : false
Missing Date 2020-12-17
API DATA : 2020-12-19 Check Date : 2020-12-18
Logic Check : false
Missing Date 2020-12-18
API DATA : 2020-12-20 Check Date : 2020-12-19
Logic Check : false
Missing Date 2020-12-19
API DATA : 2020-12-21 Check Date : 2020-12-20
Logic Check : false
Missing Date 2020-12-20
API DATA : 2020-12-22 Check Date : 2020-12-21
Logic Check : false
Missing Date 2020-12-21
API DATA : 2020-12-23 Check Date : 2020-12-22
Logic Check : false
Missing Date 2020-12-22
API DATA : 2020-12-24 Check Date : 2020-12-23
Logic Check : false
Missing Date 2020-12-23
进程已完成,退出代码为0
您应该更改代码的这一部分
if (!checkDate.toString().equals(apiObj.get(i))) {
System.out.println("Missing Date " + checkDate);
}
至
if (!checkDate.toString().equals(apiObj.get(i))) {
System.out.println("Missing Date " + checkDate);
i--;
}