开发者

Formatting date with fmt:formatDate

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜