JSTL tag fmt:formatDate formatted date String to Date

Uses the FMT function to be introduced in JSP

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<fmt:formatDate value="${entity.ctime}" pattern="yyyy-MM-dd HH:mm"/>
Newspaper java.lang.IllegalArgumentException: Cannot convert 201311251525 of type class java.lang.String to class java.util.Date


Abnormal because ${entity.ctime} out is of type String, cannot be converted to a Date type


The following will be normal output

<fmt:formatDate value="<%=new Date() %>" pattern="yyyy-MM-dd"/>


The solution is, the first String Date and then type Date

<fmt:parseDate value="${entity.ctime}" var="date" pattern="yyyyMMddHHmm"/>

<fmt:formatDate value="${date}" pattern="yyyy-MM-dd HH:mm" />


Posted by Bartley at December 16, 2013 - 5:22 AM