I want to take date from DB and display on jsp:
2014-04-02
instead of:
2014-04-02 00:00:00.0
On jsp I tried to use c:fmt tag for formatting date:
<div class="form-group">
<span><fmt:message key="task.start"/></span>
<input class="form-control" id="firstDate" placeholder="<fmt:message key="task.start"/>"
name="start_date-${task.taskId}"
<fmt:formatDate value="${task.startDate}" var="startFormat" type="date" pattern="yyyy-MM-dd"/>
value="${startFormat}"/>
</div>
Looking on the page:
How to format it to yyyy-MM-dd format?
First you need to add the line below to head of your jsp file
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
Now you can use <fmt:formatDate>
and <fmt:parseDate>
for formatting date.
<fmt:formatDate value="${now}" pattern="yy-MMM-dd"/>
PS: In your code, I saw you had some mistakes with the jsp tag. I think it should be
<div class="form-group">
<span><fmt:message key="task.start"/></span>
<input class="form-control" id="firstDate" placeholder="<fmt:message key='task.start'/>"
name="start_date-${task.taskId}" value="<fmt:formatDate value='${task.startDate}' var='startFormat' type='date' pattern='yyyy-MM-dd'/>"
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With