You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Mike Kienenberger <mk...@alaska.net> on 2005/01/06 20:50:34 UTC

[Vel-Tools] Converting a long return type into a formatted Date

I'm trying to figure out how to convert File.lastModified (type long) into a 
formatted date in Velocity.

It appears that I need to use DateTool.toDate(Long obj) to go from a long 
value to a Date.

However, neither NumberTool nor MathTool provides a method to convert a long 
to a Long.   I can convert it to an Integer with MathTool.toInteger().  Or 
MathTool.toNumber() and -- if the number is large enough -- it'll force it 
to be a Long, but it's not guaranteed.

Perhaps DateTool should be modified to handle toDate(Number obj).   Or 
MathTool modified to provide toLong(), toFloat(), etc.   Or both.

Hopefully, I'm overlooking something obvious, which is why I posted to user 
and not dev.

Thanks,

-Mike

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


Re: [Vel-Tools] Converting a long return type into a formatted Date

Posted by Nathan Bubna <nb...@gmail.com>.
yeah, my understanding is that it is a function of java reflection
itself, rather than an intentional thing done by Velocity.  but i
could be wrong...

On Thu, 06 Jan 2005 15:39:53 -0500, Mike Kienenberger
<mk...@alaska.net> wrote:
> Nathan Bubna <nb...@gmail.com> wrote:
> > in VTL, long and Long are the same.  have you tried just using
> > DateTool.toDate(Long) with the long?
> 
> Just tried it, and it works fine.
> 
> I didn't realize that primitive types would convert like that inside nested
> method calls.  I figured (wrongly) that primitive-to-object conversions
> would only take place on the outer-most call when the value was actually
> rendered.
> 
> Thanks!
> 
> -Mike
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
>

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


Re: [Vel-Tools] Converting a long return type into a formatted Date

Posted by Mike Kienenberger <mk...@alaska.net>.
Nathan Bubna <nb...@gmail.com> wrote:
> in VTL, long and Long are the same.  have you tried just using
> DateTool.toDate(Long) with the long?

Just tried it, and it works fine.

I didn't realize that primitive types would convert like that inside nested 
method calls.  I figured (wrongly) that primitive-to-object conversions 
would only take place on the outer-most call when the value was actually 
rendered.

Thanks!

-Mike

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


Re: [Vel-Tools] Converting a long return type into a formatted Date

Posted by Nathan Bubna <nb...@gmail.com>.
in VTL, long and Long are the same.  have you tried just using
DateTool.toDate(Long) with the long?

On Thu, 06 Jan 2005 14:50:34 -0500, Mike Kienenberger
<mk...@alaska.net> wrote:
> I'm trying to figure out how to convert File.lastModified (type long) into a
> formatted date in Velocity.
> 
> It appears that I need to use DateTool.toDate(Long obj) to go from a long
> value to a Date.
> 
> However, neither NumberTool nor MathTool provides a method to convert a long
> to a Long.   I can convert it to an Integer with MathTool.toInteger().  Or
> MathTool.toNumber() and -- if the number is large enough -- it'll force it
> to be a Long, but it's not guaranteed.
> 
> Perhaps DateTool should be modified to handle toDate(Number obj).   Or
> MathTool modified to provide toLong(), toFloat(), etc.   Or both.
> 
> Hopefully, I'm overlooking something obvious, which is why I posted to user
> and not dev.
> 
> Thanks,
> 
> -Mike
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
>

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