The use of the FMT function is required in the JSP to introduce
<%@ taglib prefix= "FMT" uri= "Http://java.sun.com/jsp/jstl/fmt"%>
<fmt:formatdate value= "${item.expdate}" pattern= "Yyyy-mm-dd"/>
Reported Java.lang.IllegalArgumentException:Cannot convert 20131125 of type class java.lang.String to class Java.util.Date
Exception because ${item.expdate} is taken out as a string type and cannot be converted to a date type
The output will be normal as follows
<fmt:formatdate value= "<%=new Date ()%>" pattern= "Yyyy-mm-dd"/>
The workaround is to resolve the string to date before formatting the date.
<fmt:parsedate value= "${item.expdate}" var= "Yearmonth" pattern= "Yyyy-mm-dd"/>
<fmt:formatdate value= "${yearmonth}" pattern= "yyyy-mm"/><!--here the value can only be date type--
<c:> Label Description:
Background:
Request.setattribute ("Today", New Date ());
Front desk:
<%@ taglib uri= "http://java.sun.com/jsp/jstl/fmt" prefix= "FMT"%>
<fmt:formatdate value= "${today}"/>//Do not write type attribute, and type= "date" equivalent
<fmt:formatdate value= "${today}" type= "Time"/>//type default value is Date
<fmt:formatdate value= "${today}" type= "both"/>
<fmt:formatdate value= "${today}" datestyle= "short"/>
<fmt:formatdate value= "${today}" datestyle= "Medium"/>//datestyle= "Medium" is the default value
<fmt:formatdate value= "${today}" datestyle= "Long"/>
<fmt:formatdate value= "${today}" datestyle= "full"/>
<fmt:formatdate value= "${today}" pattern= "Yyyy/mm/dd HH:mm:ss"/>
<fmt:formatdate value= "${today}" pattern= "Yyyy/mm/dd HH:mm:ss" var= "D"/>
${D}
Results: 2010-9-20
13:03:35
2010-9-20 13:05:32
10-9-20
2010-9-20
September 20, 2010
Wednesday, September 20, 2010
2010/09/20 13:10:25
2010/09/20 13:10:56
JSTL FMT Format Time