JSTL Date comparison
U can use jstl and usebean something like this
<jsp:useBean id="now" class="java.util.Date"/>
<c:if test="${someEvent.startDate lt now}">
It's history!</c:if>
Just use <fmt:formatDate>
to extract the year from it so that you can do the math on it.
<fmt:formatDate value="${user.birthDate}" pattern="yyyy" var="userBirthYear" />
<c:if test="${userBirthYear le 1970}">
<doSomeLogic/>
</c:if>
You could also add a boolean getter to you bean:
public boolean isBirthDateAfter1970(){
return birthDate.after(dateOf1970);
}
So you can use the following EL:
<c:if test="${user.birthDateAfter1970}">
You were born after the sixties.
</c:if>
<c:if test="${date1.time > date2.time}">...</c:if>
or lt
,=
,gt
:
<c:if test="${date1.time gt date2.time}">...</c:if>
We exploit Long getTime()
method of java.util.Date
.