如果时间在两个值之间,我有一个显示警报的功能。
例如:
开始 = 07:00:00
结束 = 17:00:00
assert start != null;
int from = Integer.valueOf(start.replace(":", ""));
assert end != null;
int to = Integer.valueOf(end.replace(":", ""));
Date date = new Date();
Calendar c = Calendar.getInstance();
c.setTime(date);
int t = c.get(Calendar.HOUR_OF_DAY) * 100 + c.get(Calendar.MINUTE);
boolean isBetween = to > from && t >= from && t <= to || to < from && (t >= from || t <= to);
a = isBetween ? 1 : 0;
if(a == 1) {
alert_f();
// a is never 1...
}
问题是a
永远不会是 1,即使实际时间在开始和结束之间。
任何想法为什么?