commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dion Gillard" <dion.gill...@gmail.com>
Subject Re: [jelly] How to build a date object with current time in GMT?
Date Fri, 26 Jan 2007 11:17:34 GMT
On 1/26/07, Karr, David <david.karr@wamu.net> wrote:
> I have a Jelly script that puts the current time into a string.  It
> works ok, but I'm realizing I need to convert the time to GMT before
> putting it into the string.  It's straightforward to do this in Java,
> but I'm having trouble figuring out how to do this in the limited Java
> syntax in Jelly.
>
> In Java, I might do something like this:
>
>   Calendar calendar = Calendar.getInstance();
>
> calendar.setTimeZone(TimeZone.getTimeZone(TimeZone.getAvailableIDs(0)[0]
> ));
>   date gmtDate = calendar.getDate();
>
> In Jelly, I think I can get close, but part of what I'm doing doesn't
> work.
>
> ----------
> <j:invokeStatic className="java.util.Calendar" method="getInstance"
>                 var="calendar"/>

corresponds to:
calendar = java.util.Calendar.getInstance();

> <j:invokeStatic className="java.util.TimeZone" method="getAvailableIDs"
>                 var="timezones">
>  <j:arg type="int" value="0"/>
> </j:invokeStatic>

Corresponds to:
timezones = java.util.TimeZone.getAvailableIds(0)

so far so good.

>
> <j:forEach var="timezone" begin="0" end="0" items="${timezones}">
> </j:forEach>

Not sure why you're doing this....assuming it's to get timezones[0]

>
> <j:setProperties object="${calendar}" timeZone="${timezone}"/>

How about (untried)

<j:setProperties object="${calendar}" timeZone="${timezones[0]}"/>

?

> ----------
>
> I get an unhelpful "argument type mismatch" error on the "setProperties"
> element.  I added "log:info" elements along the way to verify I was
> getting reasonable values (like the value for "timezone" resulting from
> the "forEach" loop).
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>


-- 
http://www.multitask.com.au/people/dion/
Rule of Acquisition #91: Hear all, trust nothing.

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


Mime
View raw message