Reputation: 829
After I retrieve java.util.Date
from MySQL table I have the following Date in my JSP view 2015-10-08 01:26:24.0
. It shows milliseconds. How can I get rid off them? There are no milliseconds in table2015-10-07 19:24:39
Here is my Entity:
@Entity
public class Payment {
@Temporal(TemporalType.TIMESTAMP)
private Date paymentDate;
@PrePersist
protected void onCreate() {
paymentDate = new Date();
}
}
In view
<c:out value="${payment.paymentDate}" />
Upvotes: 0
Views: 279
Reputation: 4154
The solution is nothing related to JPA. This can be achieved in many ways, one is to apply SimpleDateFormat (as @hermitmaster suggested) to your date object, or you can apply formatting on your JSP page using JSTL.
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
...
<fmt:formatDate type="both" value="${payment.paymentDate}" />
Upvotes: 1
Reputation: 155
Create a convenience method that applies a SimpleDateFormat and returns the result.
Upvotes: 1