jsp頁面使用C標籤對時間日期進行判斷
阿新 • • 發佈:2019-02-18
不多說,直接上程式碼。
<c:set var="nowDate" value="<%=System.currentTimeMillis()%>"></c:set> <c:choose> <c:when test="${nowDate-eduDetail.endTime.getTime() > 0}"> <td class="am-hide-sm-only">已結束</td> <td class="am-hide-sm-only"><s:property value="#attr.eduDetail.beginTime " /></td> <td class="am-hide-sm-only"><s:property value="#attr.eduDetail.endTime " /></td> </c:when> <c:when test="${nowDate-eduDetail.beginTime.getTime() < 0}"> <td class="am-hide-sm-only">未開始</td> <td class="am-hide-sm-only"><s:property value="#attr.eduDetail.beginTime " /></td> <td class="am-hide-sm-only"><s:property value="#attr.eduDetail.endTime " /></td> <td> </c:when> <c:otherwise> <td class="am-hide-sm-only">進行中</td> <td class="am-hide-sm-only"><s:property value="#attr.eduDetail.beginTime " /></td> <td class="am-hide-sm-only"><s:property value="#attr.eduDetail.endTime " /></td> <td> </c:otherwise> </c:choose>
注意,如果不加上 " .getTime()"則會報錯java.lang.IllegalArgumentException: Cannot convert 16-4-30 上午12:00 of type class java.sql.Date to Number