<td style="font: normal 宋体; font-size: 9pt;" height="40"> 查询年份: <input type="text" id="time" name="time" onChange="week(3)" class="Wdate" value='<%=now%>' style="font: normal 宋体; font-size: 9pt; width: 80px" onfocus="WdatePicker({readOnly:true,dateFmt:'yyyy'})" /> 查询时间: <select id="week" value="" style="font: normal 宋体; font-size: 9pt; width: 220px" onChange="calcu(3)"></select> <input type="button" id="fanhui" name="fanhui" style="font: normal 宋体; font-size: 9pt;" value="查询" onClick="calcu(2);"> <label id="label"></label> </td>
? <script type="text/javascript"> var startDate; var endDate; function calcu(objct) { var nowYear = document.getElementById("time").value;//当前年 //------------------------------------------------------------------------------------- var yearStart = new Date(parseInt(nowYear), 0, 1); //设置该年1.1. var firstDay = yearStart.getDay(); //星期 var yearEnd = new Date(parseInt(nowYear), 11, 31); //设置该年12.31. var endDay = yearEnd.getDay(); //星期 //------------------------------------------------------------------------------------- //判断输入是否超过最大周次. var maxWeek = 52; //该年最大周次.1.1.在周一到周四,则为该年第一周,否则为上年最后一周. if ((firstDay >= 1 && firstDay <= 4) && (endDay == 0 || endDay == 4 || endDay == 5 || endDay == 6)) { maxWeek = 53; //1.1.和12.31.都在本年,则该年有53周,否则52周 } else { maxWeek = 52; } //---------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------- //对1.1.所在周的前后几天特殊处理. if (firstDay >= 0 && firstDay <= 4) { other = firstDay - 1; } else { other = firstDay - 8; } //------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------- //时间调整,得出要计算周的起/始时间. //距离当年1.1.的总天数 days = (parseInt(document.getElementById("week").value, 10) - 1) * 7 - other; //转换成Ms....... var oneMinute = 60 * 1000; var oneHour = oneMinute * 60; var oneDay = oneHour * 24; //1.1.至1/1/70的毫秒数 var dateInMs = yearStart.getTime(); //当前所选周第一天离1/1/70的毫秒数. dateInMs += oneDay * days; //日期调整(设置1/1/70至今的毫秒数) yearStart.setTime(dateInMs); //当前所选周最后一天处理,同上. var weekEnd = new Date(parseInt(nowYear), 0, 1); var dateInMs1 = weekEnd.getTime(); dateInMs1 += oneDay * (days + 6); weekEnd.setTime(dateInMs1); //------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------- //月和日的处理,一位变两位,如:1->01. var month = yearStart.getMonth() + 1; if (month < 10) { month = "0" + month; } var day = yearStart.getDate(); if (day < 10) { day = "0" + day; } var month1 = weekEnd.getMonth() + 1; if (month1 < 10) { month1 = "0" + month1; } var day1 = weekEnd.getDate(); if (day1 < 10) { day1 = "0" + day1; } //------------------------------------------------------------------------------------- startDate = nowYear + "-" + month + "-" + day; endDate = nowYear + "-" + month1 + "-" + day1; if(startDate > endDate){ newNowYear = nowYear-1; startDate = newNowYear + "-" + month + "-" + day; } document.getElementById("label").innerHTML = "您选择的时间为:" + startDate + " ~ " + endDate; submit(objct); //document.getElementById('Ifrmname1').src="http://localhost:8080<%=request.getContextPath()%>/ReportEmitter?rpt=/CISS/11.brt¶ms=startData="+startDate+";endData="+endDate; //----------------------------------------------------------