Re: Formatting a date

Alex Twisleton-Wykeham-Fiennes <[email protected]> Mon, 27 Mar 2006 11:13:20 +0100
Newsgroups gmane.comp.java.webmacro.user
Message-ID <[email protected]>
On Mon 27 March 2006 11:00, Marc Palmer wrote:
> On 27 Mar 2006, at 02:47, Sven Schliesing wrote:
> > That's exactly what I looked for.
>
> There's another, potentially cleaner way...
>
> ----------------- "mymacros.wmm":
>
> #macro formatDate($d)
>     $Text.formatDate($d, "dd.MM.yyyy, HH:mm")
> #end
>
> ----------------- "yourtemplate.wmt":
>
> #include as macro "mymacros.wmm"
>
> #formatDate($createdAt)

Just to jump in for a moment - this will create a new SimpleDateFormat object 
every single time that it is invoked.  If you know that you are going to be 
formatting a lot of different dates with the same format then it is 
considerably more efficient to drop in a dedicated wrapper around an instance 
of SimpleDateFormat that gives you the format that you want as otherwise each 
time that you invoke it, it will have to parse your "dd.MM.yyyy, HH:mm" 
format string, build the internal representation and then format the Date 
which is relatively expensive.

<snip>

Alex


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642