You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Jason Mansfield <JM...@espresso.co.uk> on 2007/06/20 19:43:10 UTC

Date formatting from a string

Hi,

I am trying to format a string that contains a date as a number of milliseconds since 1970 (in text format) in my velocity template.

I realise that it should be a long, but in this instance we have to deal with the number being represented as a string.

Is there a way of converting the string representation into a date using either DateTools or other Java object methods?

Many thanks

Jason

Re: Date formatting from a string

Posted by Nathan Bubna <nb...@gmail.com>.
Use the NumberTool to convert it to a Number, then use the DateTool to
convert that to a Date:

#set( $myMillisAsNumber = $number.toNumber($myMillisAsString) )
#set( $myMillisAsDate = $date.toDate($myMillisAsNumber) )

or you can always extend the DateTool and add your own method to do it directly.

On 6/20/07, Jason Mansfield <JM...@espresso.co.uk> wrote:
> Hi,
>
> I am trying to format a string that contains a date as a number of milliseconds since 1970 (in text format) in my velocity template.
>
> I realise that it should be a long, but in this instance we have to deal with the number being represented as a string.
>
> Is there a way of converting the string representation into a date using either DateTools or other Java object methods?
>
> Many thanks
>
> Jason
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org