【发布时间】:2018-08-21 14:32:04
【问题描述】:
我正在尝试将当前日期与存储在数组中的日期进行比较,但我无法使用 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"。我找不到我犯了什么错误,谁能帮忙找出错误?
【问题讨论】:
-
代替toast使用日志
-
使用调试器。或记录案例。
-
使用 Logcat 查看您的日期是如何保存和显示的。
-
怎么做,兄弟!在 logcat 中我看不到任何错误@Sotiris M. Magionas
-
看我下面的帖子
标签: android datetime datetime-comparison