JSP 比较时间字段与当前时间大小进行相关显示

来源:互联网 发布:java classpath jar包 编辑:程序博客网 时间:2024/06/06 04:22

endTime 是我数据字段的名称.为date类型

方法1:

<c:set var="currentTime" value="<%= new Date()%>"></c:set><c:if test="${currentTime.time > act.endTime.time}">    相关显示....</c:if>


说明:如果是date类型的话需要转化为毫秒。 格式为 ${time1.time}


方法2:


<c:set var="currentTime" value="<%= System.currentTimeMillis()%>"></c:set><c:if test="${currentTime> act.endTime.time}">    相关显示....</c:if>


说明: 因为我设置的当前时间为毫秒值。所以直接可以用就行。


方法3:


<% request.setAttribute("currentTime", new Date()); %><c:if test="${currentTime> act.endTime.time}">    相关显示....</c:if>