/这里是调用 的地方
if (islate) {
if (compTime(tmp, "09:10", "lt")) {// 如果小于9:10,就不迟到
islate = false;
}
}
if (isearlyLeft) {
if (compTime(tmp, "17:00", "gt")) {// 如果大于17:00,就不早退
isearlyLeft = false;
}
}
/java 比较两时间字符串大小 ,实现 时间上的迟到、早退判断
public static boolean compTime(String s1, String s2, String gtlt) {
if (s1.indexOf(":") < 0 || s1.indexOf(":") < 0) {
System.out.println("格式不正确");
} else {
String[] array1 = s1.split(":");
int total1 = Integer.valueOf(array1[0]) * 3600
+ Integer.valueOf(array1[1]) * 60
// + Integer.valueOf(array1[2]);
;
// System.out.println(total1);
String[] array2 = s2.split(":");
int total2 = Integer.valueOf(array2[0]) * 3600
+ Integer.valueOf(array2[1]) * 60;
// + Integer.valueOf(array2[2]);
// System.out.println(total2);
if ("gt".equalsIgnoreCase(gtlt)) {// 大于等于
return total1 - total2 >= 0 ? true : false;
} else if ("lt".equalsIgnoreCase(gtlt)) {
return total1 - total2 <= 0 ? true : false;
}
}
return false;
}