Reputation: 2285
I'm trying to convert a string object that is formatted in a date format (i.e. 2013-12-14 10:00:00.0) and is passed to the jsp
as such, into another date format (i.e. 12/14/13 10:00:00 AM) on the jsp. I've tried the following lines of code trying to parse the string "date" (which happens to be in a certain date format) to an actual date format:
<fmt:parseDate value="${row.date}" type="date" pattern="yyyy-MM-dd hh:mm:ss.S" var="formatedDate"/>
<td class="dataField"><fmt:formatDate value="${formatedDate}" type="date" pattern="MM/dd/yy hh:mm:ss a"/></td>
But I'm getting the following exception in my console:
16:14:01,265 ERROR [[springapp]] Servlet.service() for servlet springapp threw exception java.text.ParseException: Unparseable date: "2013-12-14 10:00:00.0" at java.text.DateFormat.parse(DateFormat.java:337)
Does anyone have a better idea why this is not working?
Upvotes: 0
Views: 10533
Reputation: 1850
I tried same code, the problem was in format date you should use HH instead of hh
<fmt:parseDate value="${row.date}" type="date" pattern="yyyy-MM-dd HH:mm:ss.S" var="formatedDate"/>
<td class="dataField"><fmt:formatDate value="${formatedDate}" type="date" pattern="MM/dd/yy hh:mm:ss a"/></td>
Upvotes: 2