I trying to format a date using fmt:formatDate.
<c:forEach items="${list}" var="item">
<tr>
<!--some other columns-->
<td align="left">
<fmt:parseDate value="${item.date}" type="both" var="date"/>
<fmt:formatDate value="${date}" type="both" pattern="dd/MM/yyyy H:m"/>
</td>
<!--some other columns-->
</tr>
</c:forEach>
but I get this exception:
java.text.ParseException: Unparseable date: "2010-12-12 16:00:00"
All I want is to show the var date this way: 12/12/2010 16:00. How can I achieve this?
Thanks in advance.
You need to specify the parse pattern.
<fmt:parseDate value="${item.date}" pattern="yyyy-MM-dd HH:mm:ss" var="date"/>
<fmt:formatDate value="${date}" pattern="dd/MM/yyyy HH:mm" />
Normal practice, however, is to store dates as java.util.Date
, not as java.lang.String
. Then you can just do:
<fmt:formatDate value="${item.date}" pattern="dd/MM/yyyy HH:mm" />
Use as much as possible the right type for the value. It will become more easy to handle it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With