首页 > 技术文章 > 关于查询时间的几个问题?

banxian-yi 2016-04-06 00:15 原文

     效果图:

     

1、xml中sql日期查询写法:

<if test="beginInDate != null and beginInDate != ''">
     AND t.CREATE_DATE <![CDATA[ >= #{beginInDate} ]]>
</if>
<if test="endInDate != null and endInDate != ''">
     AND t.CREATE_DATE <![CDATA[ <= #{endInDate} ]]>
</if>

2、如何设置结束时间为23:59:59?

controller中的list里:

if(bean.getEndInDate()!=null && !bean.getEndInDate().equals("")){
     Date result = PublicUtils.getLastTime(bean.getEndInDate());
     bean.setEndInDate(result);}

调用公共类的方法:

    /**
     * 返回日期最后时间:yyyy-MM-dd 23:59:59
     */
    public static Date getLastTime(Date currentDate){
        Date result = new Date();
        if(currentDate==null){
            return result;
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            String t = sdf.format(currentDate)+" 23:59:59";
            result = df.parse(t);
        } catch (ParseException e) {
            return result;
        }
        return result;
    }

3.日期查询页面中的写法:

 <li><label>创建日期:</label>
        <input id="begindate" name="beginInDate" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
        value="<fmt:formatDate value="${toolSet.beginInDate}" pattern="yyyy-MM-dd"/>"
             onclick="WdatePicker({maxDate:'#F{$dp.$D(\'enddate\')}'})"/> -                
        <input id="enddate" name="endInDate" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
             value="<fmt:formatDate value="${toolSet.endInDate}" pattern="yyyy-MM-dd"/>"
                    onclick="WdatePicker({minDate:'#F{$dp.$D(\'begindate\')}'})"/>
</li>

 

推荐阅读