如何将日期格式设置为" yyyy-MM-dd& quot;与JSTL? [英] How to use format date as "yyyy-MM-dd" with JSTL?
本文介绍了如何将日期格式设置为" yyyy-MM-dd& quot;与JSTL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从数据库获取日期并显示在jsp上:
I want to take date from DB and display on jsp:
2014-04-02
2014-04-02
代替:
2014-04-02 00:00:00.0
2014-04-02 00:00:00.0
在jsp上,我尝试使用 c:fmt 标记设置日期格式:
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>
在页面上查看:
如何将其格式化为 yyyy-MM-dd 格式?
How to format it to yyyy-MM-dd format?
推荐答案
首先,您需要在jsp文件的开头添加以下行
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" %>
现在您可以使用< fmt:formatDate>
和< fmt:parseDate>
设置格式日期.
Now you can use <fmt:formatDate>
and <fmt:parseDate>
for formatting date.
<fmt:formatDate value="${now}" pattern="yy-MMM-dd"/>
PS:在您的代码中,我看到您在使用jsp标记时遇到了一些错误.我认为应该是
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>
这篇关于如何将日期格式设置为" yyyy-MM-dd& quot;与JSTL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文