判断两个日期是否超过24小时!
print?public class Test {public static void main(String[] args) {
String date1="2013-06-24 12:30:30"; //
String date2="2013-06-26 12:30:31";
try {
if(jisuan(date1,date2)){
System.out.println("可用");
}else{
System.out.println("已过期");
}
} catch (Exception e) {
// TODO: handle exception
}
}
//判断是否超过24小时
public static boolean jisuan(String date1, String date2) throws Exception {
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-M-d HH:mm:ss");
java.util.Date start = sdf.parse(date1);
java.util.Date end = sdf.parse(date2);
long cha = end.getTime() - start.getTime();
double result = cha * 1.0 / (1000 * 60 * 60);
if(result<=24){
//System.out.println("可用");
return true;
}else{
//System.out.println("已过期");
return false;
}
}
}
补充:软件开发 , Java ,