Reputation: 3
I know this is a very common question but i can't find any answer useful for me. I'm working in a spring application using hibernate and getting data from an oracle database. When i insert data into the database one of the fields is the current date that i format like this:
DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
Date date = new Date();
And it works fine!
My problem is that when i want to print that date in a JSP it returns like this:
Fecha del mensaje: 2013-06-04 00:00:00
I want to display the date in this way: dd-MMM-YYYY but i just don't know how. As i said before i'm working with spring and hibernate templates.
The code in my controllers is :
@RequestMapping(value="/detalle", method=RequestMethod.GET)
public String detail(HttpServletRequest req, Map<String, Object> map){
map.put("details", service.solPorId(req.getParameter("id_sol")));
map.put("files", service.getFileId(req.getParameter("id_sol")));
return "gestor/detalles";
}
The method service.solPorId("anyId")
just do a select * from ... where id_sol=anyId
And I'm calling the data in the JSP like this:
<c:forEach items="${details}" var="det">
<h2>Solicitud No. <c:out value="${det.id_sol}" /></h2>
<p>Alumno: <c:out value="${det.nombre}" /> <c:out value="${det.apellido}" /></p>
<p>Especialidad: <c:out value="${det.especialidad}" /></p>
<p>Código: <c:out value="${det.codigo}" /></p>
<p>Ciclo: <c:out value="${det.ciclo}" /></p>
<p>Asunto: <c:out value="${det.asunto}" /></p>
<p>Cuerpo del mensaje:</p>
<p><c:out value="${det.descripcion}" /></p>
<p>Fecha del mensaje: <c:out value="${det.fecha}" /></p>
So anybody can help me in how to format that date ? Thanks in advance, and sorry for my bad english :(
Upvotes: 0
Views: 1575
Reputation: 5269
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
....
<fmt:formatDate value="${det.fecha}" pattern="dd-MMM-YYYY" />
Upvotes: 1