Search code examples
jspjstldate-comparison

compare date with current time in jstl


Hello I'm trying compare a date with current time using jstl in a jsp file. How can I compare a date with the current time using jstl? I have this:

<jsp:useBean id="currentDate" type="java.util.Date"/>  
<fmt:formatDate var="now" value="${currentDate} pattern="yyyy-MM-dd"/>  

<c:if test="${ h.time < now }">
  <h1>print something</h1>
</c:if>

thanks in advance!


Solution

  • convert the time to a date and compare it with the current date.

    Conversion to date:

    <jsp:useBean id="dateValue" class="java.util.Date" />
    <jsp:setProperty name="dateValue" property="time" value="${h.time}" />
    

    Comparision:

    <c:if test="${dateValue le now}">
        //do something
    </c:if>