标签:
function check() { var startTime=$("#sTime").val(); var endTime=$("#eTime").val(); if(startTime==""){ alert("请输入开始时间!"); return; } if(endTime==""){ alert("请输入结束时间!"); return; } if(!checkEndTime(startTime,endTime)){ alert("结束时间必须晚于开始时间!"); return; } var sp=DateDiff(startTime,endTime); if(sp.Days>90) { alert("只能查询三个月内的数据!") return; } } function checkEndTime(startTime,endTime){ var start=new Date(startTime.replace("-", "/").replace("-", "/")); var end=new Date(endTime.replace("-", "/").replace("-", "/")); if(end<start){ return false; } return true; } function DateDiff(sDate1, sDate2){ //sDate1和sDate2是字符串 yyyy-MM-dd格式 var aDate, oDate1, oDate2, iDays, ihours, iminutes, iseconds; aDate = sDate1.split("-"); oDate1 = new Date(aDate[1] + ‘-‘ + aDate[2] + ‘-‘ + aDate[0]);//转换为MM-dd-yyyy格式 aDate = sDate2.split("-"); oDate2 = new Date(aDate[1] + ‘-‘ + aDate[2] + ‘-‘ + aDate[0]); var timeSpan = {}; var TotalMilliseconds = Math.abs(oDate1 - oDate2);//相差的毫秒数 timeSpan.Days = parseInt(TotalMilliseconds / 1000 / 60 / 60 /24); timeSpan.TotalHours = parseInt(TotalMilliseconds / 1000 / 60 / 60); timeSpan.Hours = timeSpan.TotalHours % 24; timeSpan.TotalMinutes = parseInt(TotalMilliseconds / 1000 / 60); timeSpan.Minutes = timeSpan.TotalMinutes % 60; timeSpan.TotalSeconds = parseInt(TotalMilliseconds / 1000); timeSpan.Seconds = timeSpan.TotalSeconds % 60; timeSpan.TotalMilliseconds = TotalMilliseconds; timeSpan.Milliseconds = TotalMilliseconds % 1000; return timeSpan; }
标签:
原文地址:http://www.cnblogs.com/longling2344/p/5341365.html