How do I format and display a Date
object in a JSP, most preferably using JSTL and EL but any other solution is welcome? I can not change the bean object.
I have the following class:
import java.util.Date;
public class Person {
private Date myDate;
public Date getMyDate() {
return myDate;
}
public void setMyDate(Date myDate){
this.myDate = myDate;
}
}
I am trying to display the date in this object in a JSP page. When I do this <c:out value="${person.myDate} />
it prints this in the page. 2013-06-08 00:00:00.0
What I want to do is remove the time portion of the date and format it to MM-dd-yyyy
.
I tried this:
<c:set var="myDate" value="${person.myDate }"/>
<fmt:formatDate value="${myDate}" type="date" var="formattedDate"/>
and it gave me the following error
Unable to convert string '${myDate}' to class java.util.Date for attribute value: java.lang.IllegalArgumentException: Property Editor not registered with the PropertyEditorManager
Then I tried the following:
<c:set var="myDate" value="${person.myDate }"/>
<fmt:parseDate value="${myDate }" var="parsedDate" pattern="MM-dd-yyyy"/>
<c:out value="${parsedDate }"/>
and I got:
Unparseable date: "${myDate }"