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

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" οnfοcus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"></input></td>
  		<td width="60px">结束时间:</td><td width="80px"><input type="text" id="timeEnd" name="timeEnd" οnfοcus="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);   


 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值