1、下载My97DatePicker组件包
解压后放在web项目与jsp文件并列位置,即WebContent下
2、在页面中引入该组件js文件:
<script type="text/javascript" src="My97DatePicker/WdatePicker.js" charset=utf-8>
3、例子
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Insert title here</title> <script type="text/javascript" src="My97DatePicker/WdatePicker.js" charset=utf-8> </script> <script type="text/javascript"> </script> </head> <body> <form action="" method="post"> <span>起始时间:</span> <input id="startDate" name="startDate" class="Wdate" type="text" onfocus="WdatePicker()" /> <span>结束时间:</span> <input id="endDate" name="endDate" class="Wdate" type="text" onfocus="WdatePicker()" /> <input type="submit" value="确定" /> </form> </body> </html>
其他页面接受这个两个时间代码:
String startDate=new String(request.getParameter("startDate").getBytes("ISO-8859-1"),"utf-8");
String endDate=new String(request.getParameter("endDate").getBytes("ISO-8859-1"),"utf-8");
数据库查询两个时间段之间的数据代码(时间字段为date)
String sql="select * from 表名 where date between '"+startDate+"' and '"+endDate+"'";
注意:如果出现中文乱码问题,修改My97DatePicker文件夹下的config.js文件,编码方式改为utf-8:
charset:'UTF-8'