fmt:formatDate无法按预期工作 [英] fmt:formatDate not working as expected
问题描述
我正在尝试将进入jsp的java.util.Date对象格式化为"yyyy-MM-dd hh:mm:ss"模式,但仍将其打印为其他格式(默认可能)格式.
I am trying to format a java.util.Date object, that I am getting in my jsp, into a pattern of "yyyy-MM-dd hh:mm:ss" but it still prints it in a different (default probably) format.
我已经使用此语句包含了标签库-
I have included the taglibrary using this statement -
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
并且我正在使用以下代码行将其打印为表单元格中的值-
and I am printing this as a value in a cell of a table using the following code line -
<td><fmt:formatDate pattern="yyyy-MM-dd hh:mm:ss" value="${proposal.creationDate}"/></td>
但是它仍然显示如下-
Wed May 24 00:00:00 IST 3911
有人可以建议我可能做错了吗.
Can someone please suggest, what I might be doing wrong.
推荐答案
我遇到了同样的问题.在尝试格式化日期之前,我可以通过设置区域设置来解决此问题:
I had this same problem. I was able to fix it by setting a locale before attempting to format the date:
<fmt:setLocale value="en_US" />
<fmt:formatDate value="${now}" pattern="yyyy-MM-dd" />
这解决了问题,但我不知道为什么.
This fixed the problem, but I don't know why.
这篇关于fmt:formatDate无法按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!