我正在尝试将当前日期与存储在数组中的日期进行比较,但我无法使用if
条件比较日期。
我使用此代码来比较日期:
DateFormat TO = new SimpleDateFormat("yyyy-MM-dd ");
Today = TO.format(Calendar.getInstance().getTime());
for (int i = 0; i < jsonArray.length(); i++) {
// Today has a value 2018-03-13
// ScheduleDates[i] has a value 2018-03-13
// ScheduleDates[10] has a value 2018-03-13
if (Today.equals(ScheduleDates[i])) {
Toast.makeText(Main2Activity.this, "Match Found" + ScheduleDates[i] + "--"
+ StartTimes[i] + "--" + Endtimes[i], Toast.LENGTH_LONG).show();
break;
} else {
Toast.makeText(Main2Activity.this, "Match Not Found", Toast.LENGTH_LONG).show();
break;
}
}
但是当我运行循环时,它只显示"match not found"
. 我找不到我犯了什么错误,有人可以帮忙找出错误吗?