根据开始时间、结束时间检索

jsp代码

 

需要引入的js文件

<script charset="gb2312" type="text/javascript" src="date/WdatePicker.js"></script>
<script  type="text/javascript" src="js/jquery/jquery-1.2.6.min.js"></script>
<script  type="text/javascript" src="js/jquery/checktime.js"></script>

<div class="font_content" align ="center">
   <form name ="search"  method ="post" action="depOrd_listByKeyword.action"  autocomplete="off" onSubmit="return checktime()">
   <table border="0" align="center" width="100%">
    <tr>
    	<td width="10px"></td>
  		<td width="50px">关键字:</td><td width="80px"><input type="text" id="keyword" name="keyword"></input></td>
  		<td width="60px">开始时间:</td><td width="80px"><input type="text" id="timeBegin" name="timeBegin" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"></input></td>
  		<td width="60px">结束时间:</td><td width="80px"><input type="text" id="timeEnd" name="timeEnd" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"></input></td>
  		<td><input type="submit" value="搜索"  /></td> 
  	</tr>
  	</table>
  	</form>
  </div>


checktime.js文件如下,其实是copy网上别人的代码

 

function checktime(){
if ($("#timeBegin").length > 0 && $("#timeEnd").length > 0) { 
if (Date.parse(TimeFormatToSQL($("#timeBegin").val()).replace("-", "/")) >
Date.parse(TimeFormatToSQL($("#timeEnd").val()).replace("-", "/"))) { 
{
	alert("开始时间必须小于结束时间!"); 
// $("#txtBeginSearchTimeByBE").focus(); 
	return false; 
}
}
///<summary>
///    将传递的时间值转换为SQL识别的时间格式
///<param name="strTime">时间(正常的页面显示时间格式)</param>
///</summary>
function  TimeFormatToSQL(strTime) {
var strResult = "";
var strTemp = "";
for (var i = 0; i < strTime.length; i++) {
strTemp = strTime.substr(i, 1);
if (strTemp == "年" || strTemp == "月")
    strResult += "-";
else
    if (strTemp == "日" || strTemp == "秒") {
        if (strTemp == "日")
            strResult += "|";
        else
            strResult += "";
    }
    else
        if (strTemp == "时" || strTemp == "分")
            strResult += ":";
        else
            strResult += strTemp;
}
var strArgDateTime = strResult.split('|');  //此时的时间格式可能为2010-11-11 11: 或2010-11-11 11等格式
if (strArgDateTime.length == 1) {
//日期部分进行处理
var strArgDate = strArgDateTime[0].split('-'); //此时对时间部分进行处理,可能为11: 11 或11:00等格式
if (strArgDate.length == 2) {
    if (strArgDate[1].length < 1)
        strResult = strArgDate[0];
    else
        strResult = strArgDateTime[0] + "-01";
} else
    if (strArgDate.length == 3) {
        if (strArgDate[2].length < 1)
            strResult = strArgDate[0] + "-" + strArgDate[1] + "-01";
    }
}
else
if (strArgDateTime.length == 2) {
    //时间部分进行处理
    var strArgTime = strArgDateTime[1].split(':'); //此时对时间部分进行处理,可能为11: 11 或11:00等格式
    if (strArgTime.length == 1) {
        strResult = strArgDateTime[0] + " " + strArgDateTime[1] + ":00:00"
    } else
        if (strArgTime.length == 2) {
            if (strArgTime[1].length < 1)
                strResult = strArgDateTime[0] + " " + strArgDateTime[1] + "00"
            else
                strResult = strArgDateTime[0] + " " + strArgDateTime[1] + ":00"
        } else
            if (strArgTime.length == 3) {
                if (strArgTime[2].length < 1)
                    strResult = strArgDateTime[0] + " " + strArgDateTime[1] + "00"
            }
}
return strResult;
}
}}


 

jquery.js可以在jquery官网下载,而WdatePicker.js也可以在http://www.my97.net/ 官网下载

 

后台hibernate处理部分代码,

hql ="from Av a where a.createtime >= (:timeBegin)";

Date timeBegin = getTimeBegin();

Timestamp ts = new Timestamp(timeBegin.getTime()); 
   query.setTimestamp("timeBegin",ts);   


 

你可能感兴趣的:(根据开始时间、结束时间检索)