Re: Formatting a date
Endre Stølsvik <[email protected]> Mon, 27 Mar 2006 21:54:52 +0200 (CEST)
| Newsgroups | gmane.comp.java.webmacro.user |
|---|---|
| Message-ID | <[email protected]> |
On Mon, 27 Mar 2006, Alex Twisleton-Wykeham-Fiennes wrote: | On Mon 27 March 2006 11:28, Marc Palmer wrote: | > On 27 Mar 2006, at 11:13, Alex Twisleton-Wykeham-Fiennes wrote: | > > 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. | > | > You're absolutely right, but that can be dealt with using a macro | > plus a #bean to create a "static" shared instance of the formatter? | | I'll also look at making $Text.formatDate cache the SimpleTextFormat objects | that it creates and run some profiling to see whether or not this is really | an advantage... And where should this cache reside? In which context? Who's gonna clean it? When? How? (And how do I reload my webapp in Tomcat?) Caches on every corner, under every rock, in every creek, and in other unknown places, is the way to evil code. Regards, Endre. ------------------------------------------------------- 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