I am using Calendar type in Java and I would like to display formatted date in JSTL.
I was trying:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<fmt:parseDate var="date" type="date" dateStyle="short" value="${photo.dateCreated}" />
<c:out value="${data}" />
But it doesn’t work:
java.text.ParseException: Unparseable date
Can JSTL format Calendar type?
No, it can only format the
java.util.Datetype since it usesDateFormat#format()under the hoods. UseCalendar#getTime()to grab it from theCalendar.Note that you need
fmt:formatDatefor this, notfmt:parseDate. Formatting is converting aDateobject into a human readable date string and parsing is converting a human readable date string into aDateobject.