有时候在一些查询的后台,时间作为一个条件是必须的,我们要做的是,一打开查询页面,就会有前30天的默认时间间段。如何做呢?
是计算出来之后把值放在时间查询框input里面的value就可以了。具体如下:
<%
?? //获取系统当日日期
?? Calendar cal = Calendar.getInstance(TimeZone.getDefault());
??????? String DATE_FORMAT = "yyyy-MM-dd";
??????? SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);??
??????? sdf.setTimeZone(TimeZone.getDefault());
?? String dateOfToday=sdf.format(cal.getTime());
?? String DATE_FORMAT2 = "yyyy-MM-01";
??????? SimpleDateFormat sdf2 = new SimpleDateFormat(DATE_FORMAT2);??
??????? sdf2.setTimeZone(TimeZone.getDefault());
???????
??????? String firstDayOfMonth=sdf2.format(cal.getTime());
??
??
?? String defaultStartDate = (String)Charset.trim(request.getAttribute("startDate"));
?? String defaultOverDate = (String)Charset.trim(request.getAttribute("overDate"));??
????
?? if(defaultStartDate.length()<1 && defaultOverDate.length()<1){
??? defaultStartDate=firstDayOfMonth;
??? defaultOverDate=dateOfToday;
?? }
%>
?
?????? <td>
??????? 起始时间:
?????? </td>
?????? <td>
??????? <input type="text" style="cursor:text" id="sbox" name="startDate" value="<%=defaultStartDate%>"
???????? size="15" onfocus="changeDate(this)" style="width:150px">
?????? </td>
?????? <td>
??????? 结 束 时 间:
?????? </td>
?????? <td>
??????? <input type="text" style="cursor:text" id="ebox" name="endDate" value="<%=defaultOverDate%>"
???????? size="15" onfocus="changeDate(this)" style="width:150px">
?????? </td>