-
Check date using jstl
Please Help,
I need to do the following:
I've mixed a bit of code and pseudo code here, hope somebody can fill in the pseudocode for me.
<c:forEach var="date" in items="${listOfJavaUtilDates}">
<c:if test="${date} is the same date, but not necessarily time as ${someDate}">
<td><fmt:formatDate type="date" value="${date}" /></td>
</c:if>
</c:forEach>
<c:if test="if no java.util.Date were in the list which matched ${someDate}">
<td>No times found</td>
</c:if>
-
A java.util.Date does not have the concept of a date portion, or a time portion. It is simply a long int, representing milliseconds.
So to compare the date part you would have to either format the Dates into Strings with just the date portion and do an equals() on that, or something involving Calendar. The formaer is probably the easiest for you.
-
Thanks,
I would do by storing the output of fmt:formatDate into a var right?
How about the conditional print if no dates were matched?
-
That sounds about right (for the format stuff).
Presumably there's a test for List size you can do?
I haven't done this stuff for a couple of years...:)
-
Ah yes of course.
<c:if test="${empty listOfJavaUtilDates}" >
<td>No times found</td>
</c:if>
Great, thanks for your help :)