日期处理
---------------------start------------------------
<html-el:form action="/note/queryNote.do" method="post"> //表单
<tr>
<td class="inputtabletd1">查询开始时间:</td>
<td class="inputtabletd3">
<html-el:text property="agTran.cxkssj" onclick="WdatePicker({startDate:'%y-%M-%d %h:%m:%s',dateFmt:'yyyyMMdd',alwaysUseStartDate:true})" readonly="true"></html-el:text>
<img src="../images/common_star.gif">
<font color="red"><span id="dateErr"></span></font>
</td>
<td class="inputtabletd1">查询结束时间:</td>
<td class="inputtabletd3">
<html-el:text property="agTran.cxjzsj" onclick="WdatePicker({startDate:'%y-%M-%d %h:%m:%s',dateFmt:'yyyyMMdd',alwaysUseStartDate:true})" readonly="true"></html-el:text>
<img src="../images/common_star.gif">
<font color="red"><span id="dateEndErr"></span></font>
</td>
</tr>
</html-el:form>
<script type="text/javascript">
function query(obj){
var cxfs=$('agTran.cxfs').value; //查询方式 15天 / 15--90
var cxxx=$('agTran.cxxx').value; //查询选项 按日 / 7天
var cxkssj=$F('agTran.cxkssj');
var cxjzsj=$F('agTran.cxjzsj');
var sysdate = "<%=new SimpleDateFormat("yyyyMMdd").format(new Date()) %>";
var date15=dateToString(14);
var date16=dateToString(15);
var date90=dateToString(89);
//日期非空验证
if(cxkssj==''){
$("dateErr").innerHTML= "起始日期不能为空!";
$("agTran.cxkssj").focus();
return false;
}else{$("dateErr").innerHTML= "";};
if(cxjzsj==''){
$("dateEndErr").innerHTML= "截止日期不能为空!";
$("agTran.cxjzsj").focus();
return false;
}else{$("dateEndErr").innerHTML= "";};
//起始截止日期合法性验证
if(cxjzsj>sysdate){
$("dateEndErr").innerHTML= "截止日期不能大于当前日期!";
$("agTran.cxjzsj").focus();
return false;
}else{$("dateEndErr").innerHTML= "";};
if(cxkssj>cxjzsj){
$("dateErr").innerHTML= "起始日期不能大于结束日期!";
$("agTran.cxkssj").focus();
return false;
}else{$("dateErr").innerHTML= "";};
if (cxxx=='0'){
if(cxkssj!=''&&cxkssj<date15){
$("dateErr").innerHTML= "请选择15天内日期!";
$("agTran.cxkssj").focus();
return false;
}else{$("dateErr").innerHTML= ""}
if(cxjzsj!=''&&cxjzsj<date15){
$("dateEndErr").innerHTML= "请选择15天内日期!";
$("agTran.cxjzsj").focus();
return false;
}else{$("dateEndErr").innerHTML= ""}
}
if (cxxx=='1'){
if(cxkssj!=''&&date90>cxkssj){
$("dateErr").innerHTML= "请选择15天外-90天内日期!";
$("agTran.cxkssj").focus();
return false;
}else{$("dateErr").innerHTML= ""}
if(cxkssj!=''&&cxkssj>date16){
$("dateErr").innerHTML= "请选择15天外-45天内日期!";
$("agTran.cxkssj").focus();
return false;
}else{$("dateErr").innerHTML= ""}
if(cxjzsj!=''&&date90>cxjzsj){
$("dateEndErr").innerHTML= "请选择15天外-90天内日期!";
$("agTran.cxjzsj").focus();
return false;
}else{$("dateEndErr").innerHTML= ""}
if(cxjzsj!=''&&cxjzsj>date16){
$("dateEndErr").innerHTML= "请选择15天外-90天内日期!";
$("agTran.cxjzsj").focus();
return false;
}else{$("dateEndErr").innerHTML= ""}
//同一个月
var yearMonthS=cxkssj.substr(0,6);
var yearMonthE=cxjzsj.substr(0,6);
if(yearMonthS!=yearMonthE){
$("dateErr").innerHTML= "起始日期和截止日期必须在同一个月!";
$("agTran.cxkssj").focus();
return false;
}else{
$("dateErr").innerHTML= "";
}
}
//按日查询起始与截止需在同一日
if(cxfs=='1'){
if(cxkssj!=cxjzsj){
$("dateErr").innerHTML= "仅支持查询同一天内记录!";
$("agTran.cxkssj").focus();
return false;
}else{
$("dateErr").innerHTML= "";
}
}
var sDatestr=cxkssj.substr(0,4)+"/"+cxkssj.substr(4,2)+"/"+cxkssj.substr(6,2);
var eDatestr=cxjzsj.substr(0,4)+"/"+cxjzsj.substr(4,2)+"/"+cxjzsj.substr(6,2);
var sDate=new Date(Date.parse(sDatestr));
var eDate=new Date(Date.parse(eDatestr));
//按七日查询时间跨度不允许超过七日
if(cxfs=='2'){
if((eDate-sDate)/(1000*60*60*24)>6){
$("dateErr").innerHTML= "仅支持查询七天内记录!";
$("agTran.cxkssj").focus();
return false;
}else{$("dateErr").innerHTML= "";};
}
noteBean.action = "showNote.do";
noteBean.submit();
}
</script>