Below. > -----Original Message----- > From: Dion Gillard [mailto:[EMAIL PROTECTED] > Sent: Friday, January 26, 2007 6:47 AM > To: Jakarta Commons Users List > Subject: Re: [jelly] How to build a date object with current > time in GMT? > > On 1/27/07, Karr, David <[EMAIL PROTECTED]> wrote: > > Below. > > > -----Original Message----- > > > From: Dion Gillard [mailto:[EMAIL PROTECTED] > > > Sent: Friday, January 26, 2007 3:18 AM > > > To: Jakarta Commons Users List > > > Subject: Re: [jelly] How to build a date object with > current time in > > > GMT? > > > > > > On 1/26/07, Karr, David <[EMAIL PROTECTED]> 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"/> > > > > <j:invokeStatic className="java.util.TimeZone" > > > method="getAvailableIDs" > > > > var="timezones"> > > > > <j:arg type="int" value="0"/> > > > > </j:invokeStatic> > > > > > > > > <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]}"/> > > > > > > ? > > > > That would probably be better, but both of these fail with the same > > "argument type mismatch" error. I wonder whether the "${timezone}" > > reference tries to produce a String instead of a TimeZone object? > > > > > > ---------- > > > > > > > > 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). > > Try dumping out: > > ${timezones[0].class.name}
That helped a lot. It pointed out that I was using TimeZone.getAvailableIDs(), which returns an array of String, not array of TimeZone. After I used "TimeZone.getTimeZone(String)", I got the correct TimeZone object. After that, I'm a little confused about what "Calendar.getTime()" seems to be do doing, but this is a pure Java issue, not Jelly (I verified the same behavior in a standalone Java class). If I do a "toString()" on the Calendar object, it shows the timezone to be correct (Africa something), but "getTime().toString()" shows my local time. If I do "getTime().toGMTString()" it appears to show the correct GMT time. I'm not certain what to make of these results. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
