Struts 1 Date Format Tag
Asked Answered
S

3

5

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

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

Sayer answered 18/6, 2010 at 13:12 Comment(0)
C
5

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

<%@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.SimpleDateFormat under the hoods. Its Javadoc is more descriptive about the available patterns and styles.

Coltun answered 18/6, 2010 at 13:31 Comment(0)
E
7

Can't you use format attribute? Something like:

bean:write name=xxxx  format="MMMM-dd-yyyy"
Eley answered 15/8, 2011 at 20:13 Comment(0)
C
5

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

<%@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.SimpleDateFormat under the hoods. Its Javadoc is more descriptive about the available patterns and styles.

Coltun answered 18/6, 2010 at 13:31 Comment(0)
I
3

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

Improbable answered 21/6, 2012 at 14:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.