Getting the Most Out of the Struts Tag Libraries
Subject:   how to use format with dates
Date:   2003-12-04 23:19:02
From:   anonymous2
Response to: how to use format with dates

First, I tried to some dates "the struts-way" self referencing the session in the session by putting
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

1 to 1 of 1
  1. how to use format with dates
    2004-03-09 15:28:55 [View]

    • how to use format with dates
      2008-03-12 17:54:30  rafaelpl [View]

1 to 1 of 1