标签:c style class blog code java
function checkTime(){ var dateInp=$("#dateInp").val(); var day1=Date.parse(dateInp.replace(/-/g, "/")); var nowDate = new Date(); var dateStr = nowDate.getFullYear()+"/"+(nowDate.getMonth() + 1)+"/"+nowDate.getDate(); var day2=Date.parse(dateStr); var apartTime=day1-day2; var apartDay=parseInt(apartTime / (1000 * 60 * 60 * 24)); if(apartDay ==0){ alert("不能预约当天"); return false; }else if (apartDay < 1 || apartDay > 3){ alert("预约日期超出范围"); return false; } }
最开始,day2是直接new Date()获取当前时间,这样会连毫秒一起获取,在计算差值的时候会导致当天和明天计算下来都是0
标签:c style class blog code java
原文地址:http://www.cnblogs.com/canrz/p/3759739.html