我有以下时间格式 "hh:mm:ss"。 现在我有两个时间值,例如,
Date previous_time=20:50:55
Date current_time=19:50:55
我正试图这样比较它,
if(previous_time.after(current_date)){
Log.i("Time Comparision","before is true");
System.out.println("before");
}
else if(current_time.after(previous_time)){
Log.i("Time Comparision","after is true");
System.out.println("after");
}
else {
System.out.println("nothing");
Log.i("Time Comparision not happened","");
}
但是我的两个 if 条件都不起作用。 我的问题是,当它们采用上述格式时,如何比较两个时间?
最佳答案
在您的第一行代码中,您引用的是 current_date 而不是 current_time。
这就是问题所在,或者两个日期相等,这将执行 else 中的部分。
关于java - java中如何比较时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5951393/