如何在select标签中自动增加日期

时间:2013-11-02 19:00:23

标签: javascript jquery mysql jsp

我有这个表单,其目的是过滤jsp页面中的数据。这是有效的,但我觉得这很简单而且不好,而且仅仅是2013年,我想让它增加。有没有更好更简单的方法呢?

<% 
String First = request.getParameter("firstTo");
String Second = request.getParameter("secondTo");

request.setAttribute("First", First);
request.setAttribute("Second", Second);

Connection conn = (Connection) this.getServletContext().getAttribute("conn");
String query = "SELECT * FROM blood_chemistry JOIN consult USING (idconsult) JOIN patients USING (idpatients) WHERE release_date BETWEEN '" + First + "' AND '" + Second + "'  ORDER BY plastname ASC, pfirstname ASC";
PreparedStatement ps = conn.prepareStatement(query);
ResultSet rs = ps.executeQuery(); 
%>

<form method="post" action="blood.jsp">
<p style="color:white;">
    <select name="firstTo">
       <option value="01-01-2013">January</option>
       <option value="02-01-2013">February</option>
       <option value="03-01-2013">March</option>
       <option value="04-01-2013">April</option>
       <option value="05-01-2013">May</option>
       <option value="06-01-2013">June</option>
       <option value="07-01-2013">July</option>
       <option value="08-01-2013">August</option>
       <option value="09-01-2013">September</option>
       <option value="10-01-2013">October</option>
       <option value="11-01-2013">November</option>
       <option value="12-01-2013">December</option>
   </select>To:
   <select name="secondTo">
       <option value="01-31-2013">January</option>
       <option value="02-29-2013">February</option>
       <option value="03-31-2013">March</option>
       <option value="04-31-2013">April</option>
       <option value="05-31-2013">May</option>
       <option value="06-31-2013">June</option>
       <option value="07-31-2013">July</option>
       <option value="08-31-2013">August</option>
       <option value="09-31-2013">September</option>
       <option value="10-31-2013">October</option>
       <option value="11-31-2013">November</option>
       <option value="12-31-2013">December</option>
   </select>
</p></form>

我设法做到这一点,但它只是当前的日期,我想把它设置为像01-01-2013,但年份只是递增..我怎么能这样做?

<%
  Date dNow = new Date( );
  SimpleDateFormat ft = 
  new SimpleDateFormat ("MM--dd--yyyy");
  out.print( "<h1 align=\"center\">" + ft.format(dNow) + "</h1>");
%>

1 个答案:

答案 0 :(得分:0)

如果你只想要年度动态,你可以做到这一点

Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
System.out.println(calendar.get(Calendar.YEAR));