fea jabi said:
> I am having a column which is displaying Dates in the below format.
>
> Mon Oct 10 00:00:00 EDT 2005
>
>
> But want the format to be in MM/dd/yy format.
>
> How can this be done?
>
> Thanks.

Create a class that extends ColumnDecorator and implements the decorate()
method. I included an example at the bottom of my reply.  Then just apply
that to the column you want to format:

<display:column property="myDate" decorator="ShortDateDecorator" />

Here's the class:

public class ShortDateDecorator implements ColumnDecorator
{
    /**
     * Used to format the date object.
     */
    SimpleDateFormat dateFormat = new SimpleDateFormat("M/d/yyyy");

    /**
     * transform the given object into a String representation.
     * @param columnValue Object
     * @return String
     */
    public final String decorate(Object columnValue)
    {
        String formattedDate = null;

        if (columnValue instanceof Date)
        {
             formattedDate = dateFormat.format((Date) columnValue);
        }
        else if (columnValue instanceof String)
        {
            try
            {
                 formattedDate =
dateFormat.format(dateFormat.parse((String)
columnValue));
            }
            catch (ParseException e)
            {
                //
            }
        }

        return formattedDate;
    }
}



-- 
Rick Herrick
[EMAIL PROTECTED]

I haven't got time for inner peace.

Get out of control, but appear under control. It's not bad to alarm other
people, though--it's good for them.--Hunter S. Thompson


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
displaytag-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/displaytag-user

Reply via email to