struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Lindholm <>
Subject Re: Using date to format a date
Date Mon, 19 Oct 2009 14:18:13 GMT
What I do is add a method for formatting dates (formatDateTime()) to the
action base class.  The method can then use the users Locale and TimeZone to
construct a DateFormat object.

    public String formatDateTime(Date timestamp)
        return getDateFormat().format(timestamp);

In the jsp I then I can then format the date ('updated' in this case) like

<s:property value="formatDateTime(updated)" />

If you already have a DateFormat object around you could create a method in
you action that takes both the Date and the DateFormat.

Note: Be careful storing DateFormat in the Session as DateFormat is not
synchronized so it can not used concurrently by multiple threads.

On Thu, Oct 15, 2009 at 4:03 PM, Christian Bockermann <> wrote:

> Hi list!
> I want to display a date in a user-specified manner (struts2 web-app)
> Thus, there exists a form where users can specify date-format strings, I
> validate them
> and on another page, I want to use the date-tag to display the date in the
> choosen format.
> So I have a session-property "date-format", accessible with
>        <s:property value="" />
> and would like to use this format property, something like
>        <s:date name="date" format="" />
> Unfortunately the date-tag does not allow expressions in its 'format'
> attribute. Any
> way around? Or is this simply not the right way to solve such a thing?
> Best regards,
>   Chris
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message