| Sign In/My Account | View Cart |
| Article: |
Getting the Most Out of the Struts Tag Libraries | |
| Subject: | how to use format with dates | |
| Date: | 2003-11-04 14:20:34 | |
| From: | anonymous2 | |
|
An example of using format to display dates would be welcome. You started talking about it but unfortunately the example is only for formatting currencies.
|
||
Showing messages 1 through 3 of 3.
session.setAttribute("thisSess", session);
This would great because I can always see what my session is doing.
The drawback that the time was formatted in milliseconds since 1970. So, I tried to use the struts "format" attribute, but the below 'format="HH:mm:ss"' unfortunately was useless
<<Logged in since <bean:write name="thisSess"
property="creationTime" filter="true" format="HH:mm:ss" />, last access: <bean:write
name="thisSess" property="lastAccessedTime"
filter="true" format="HH:mm:ss" />, max inactive interval: <bean:write name="thisSess"
property="maxInactiveInterval" filter="true" format="HH:mm:ss" />
so, I ended up doint it as
<<
<%
java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("HH:mm:ss");
String lastAccessTime = df.format(new java.sql.Date(session.getLastAccessedTime()));
String sessCreateTime = df.format(new java.sql.Date(session.getCreationTime()));
String maxInactiveInterval = Integer.toString(session.getMaxInactiveInterval());
pageContext.setAttribute("lastAccessTime", lastAccessTime);
pageContext.setAttribute("sessCreateTime", sessCreateTime);
pageContext.setAttribute("maxInactiveInterval", maxInactiveInterval);
%><bean:write name="lastAccessTime" filter="true" />, lastAccess: <bean:write name="lastAccessTime"
filter="true" />, maxInactive: <bean:write name="maxInactiveInterval"
filter="true" />sec
>>
if anybody knows how to do it purely in struts, please let me know at hauser@acm.org