Re: Formatting a date

"Nikhil G. Daddikar" <[email protected]> Mon, 27 Mar 2006 15:56:19 +0530
Newsgroups gmane.comp.java.webmacro.user
Organization Celoxis Technologies Pvt. Ltd.
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------070908010502080507010503
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit



I have written a static function and then use the "Functions" feature. 
The static function uses a per-request SimpleDateFormat so it is quite 
efficient.  So in webmacro I can write:

<input type="text" value="$formatInputDate($d)"> OR

<td>$formatDate($d)</td>

etc.


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.
>
> <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
> _______________________________________________
> Webmacro-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/webmacro-user
>   


--------------070908010502080507010503
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by speedo.celoxis.com id k2RAFuPT005654

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content=3D"text/html;charset=3DUTF-8" http-equiv=3D"Content-Type"=
>
</head>
<body bgcolor=3D"#ffffff" text=3D"#000000">
<br>
<br>
I have written a static function and then use the "Functions" feature.
The static function uses a per-request SimpleDateFormat so it is quite
efficient.=C2=A0 So in webmacro I can write:<br>
<br>
&lt;input type=3D"text" value=3D"$formatInputDate($d)"&gt; OR<br>
<br>
&lt;td&gt;$formatDate($d)&lt;/td&gt;<br>
<br>
etc.<br>
<br>
<br>
Alex Twisleton-Wykeham-Fiennes wrote:
<blockquote cite=3D"[email protected]" type=3D"cite"=
>
  <pre wrap=3D"">On Mon 27 March 2006 11:00, Marc Palmer wrote:
  </pre>
  <blockquote type=3D"cite">
    <pre wrap=3D"">On 27 Mar 2006, at 02:47, Sven Schliesing wrote:
    </pre>
    <blockquote type=3D"cite">
      <pre wrap=3D"">That's exactly what I looked for.
      </pre>
    </blockquote>
    <pre wrap=3D"">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)
    </pre>
  </blockquote>
  <pre wrap=3D""><!---->
Just to jump in for a moment - this will create a new SimpleDateFormat ob=
ject=20
every single time that it is invoked.  If you know that you are going to =
be=20
formatting a lot of different dates with the same format then it is=20
considerably more efficient to drop in a dedicated wrapper around an inst=
ance=20
of SimpleDateFormat that gives you the format that you want as otherwise =
each=20
time that you invoke it, it will have to parse your "dd.MM.yyyy, HH:mm"=20
format string, build the internal representation and then format the Date=
=20
which is relatively expensive.

&lt;snip&gt;

Alex


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting langua=
ge
that extends applications into web and mobile media. Attend the live webc=
ast
and join the prime developer group breaking into this new coding territor=
y!
<a class=3D"moz-txt-link-freetext" href=3D"http://sel.as-us.falkag.net/se=
l?cmd=3Dlnk&kid=3D110944&bid=3D241720&dat=3D121642">http://sel.as-us.falk=
ag.net/sel?cmd=3Dlnk&amp;kid=3D110944&amp;bid=3D241720&amp;dat=3D121642</=
a>
_______________________________________________
Webmacro-user mailing list
<a class=3D"moz-txt-link-abbreviated" href=3D"mailto:Webmacro-user@lists.=
sourceforge.net">[email protected]</a>
<a class=3D"moz-txt-link-freetext" href=3D"https://lists.sourceforge.net/=
lists/listinfo/webmacro-user">https://lists.sourceforge.net/lists/listinf=
o/webmacro-user</a>
  </pre>
</blockquote>
<br>
</body>
</html>

--------------070908010502080507010503--


-------------------------------------------------------
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