java Struts 1 日期格式标签

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3069850/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 00:12:41  来源:igfitidea点击:

Struts 1 Date Format Tag

javajspstrutsstruts-1

提问by David

Is there any tag in Struts1 tag library which can format a java.util.Dateobject?

Struts1 标签库中是否有可以格式化java.util.Date对象的标签?

In Struts 2, I can use the s:datetag, but I can't find the Struts 1 equivalent.

在 Struts 2 中,我可以使用该s:date标签,但我找不到 Struts 1 的等价物。

采纳答案by BalusC

Nothing like that appears in the Sruts tag reference. You can however use the JSTLfmt:formatDatetag for this. JSTL and Struts1 almost go hand in hand.

Sruts 标记参考中没有出现类似的内容。但是,您可以为此使用JSTLfmt:formatDate标记。JSTL 和 Struts1 几乎齐头并进。

<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
...
<p><fmt:formatDate value="${bean.date}" pattern="yyyy-MM-dd" />
<p><fmt:formatDate value="${bean.date}" type="date" dateStyle="long" />

Which should print like:

应该打印如下:

2010-06-18
June 18, 2010

It uses the java.text.SimpleDateFormatunder the hoods. Its Javadoc is more descriptive about the available patterns and styles.

它使用java.text.SimpleDateFormat引擎盖下的。它的 Javadoc 更详细地描述了可用的模式和样式。

回答by User

Can't you use format attribute? Something like:

你不能使用格式属性吗?就像是:

bean:write name=xxxx  format="MMMM-dd-yyyy"

回答by Abdelmajid Dkhaila

It works for the use of format="MM-dd-yyyy"as an attribute for bean:writetag.

format="MM-dd-yyyy"可用作bean:write标记的属性。