JS方法:
function strToDate(dateStr, separator) //dateStr格式:"yyyy-MM-dd", separator格式:"-" 字符串转换为时间 { if (typeof dateStr == 'undefined') { return new Date(); } var arr = dateStr.split(separator); var date = new Date(arr[0], arr[1] - 1, arr[2]); return date; }function isWithinDays(tmpDate, numDay) //判断tmpDate是否在numDay天内 { if (typeof tmpDate == 'undefined' || typeof num == 'undefined') { return false; } var today = new Date(); var someday = new Date(today.getFullYear(), today.getMonth(), today .getDate()); someday.setDate(someday.getDate() - (numDay-1)); return (tmpDate >= someday) && (tmpDate <= today); }function getDateStr(dayV) //获取日期字符串,dayV为0表示今天,1表示昨天,2表示前天,类推 { var d = new Date(); d.setDate(d.getDate() - dayV); var year = d.getFullYear(); //获得年份 var month = d.getMonth() + 1; //获得月份 var date = d.getDate(); //获得日期 var curDateTime = year; if (month > 9) //当月份小于9时前加0 curDateTime = curDateTime + '-' + month; else curDateTime = curDateTime + '-0' + month; if (date > 9) curDateTime = curDateTime + '-' + date; else curDateTime = curDateTime + '-0' + date; return curDateTime; }function vali(form0) {//使用 var dateStart = strToDate(form0.order_time_s.value, "-"); var dateEnd = strToDate(form0.order_time_e.value, "-"); if (dateEnd.getTime() - dateStart.getTime() < 0) { alert("起始时间不能大于结束时间!"); return false; } dateEnd.setDate(dateEnd.getDate() - 30); if ((dateEnd.getTime() - dateStart.getTime()) > 0) { alert("时间相隔不能超过31天(只允许统计一个月!)"); return false; } }function isRept(ary)//判断数组中是否有重复元素方法。 { //var ary = new Array("11","22","33","11"); var nary=ary.sort();//是按照字符编码的顺序进行排序 for(var i=0;i