You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Kirby Vandivort <kv...@ks.uiuc.edu> on 2003/05/08 18:48:51 UTC

current best practices for time zones

Let's say I want to print the current time (or choose your favorite 
time) from the server to the user's browser.

Currently, I'm storing a Date object in appropriate scope, and when
I get to the front end, I'm doing something similar to:

<bean:write name="theTime" property="dateObj" formatKey="format.time.date"/>

where format.time.date is something like hh:mm:ssa'/'yyyy.MM.dd as an
example.


So, that's the background.  I was (naively, I suppose) expecting that
struts would figure out where the user is coming from, similar to how
it does language determination, and automatically convert the Date from
the server's timezone to the user's browser's timezone.

However, this is not happening.  All dates are getting printed in the
server's timezone.

Is there a relatively clean way to handle this?  Searching the archive
returns a few hits from 2001 and I was wondering if there is anything
new on this.  Am I going to have to end up creating Locales on the
business end and managing everything there, or can I handle this
presentation-side?

Just curious what others that are a bit closer to the pulse of recent
struts than I have chosen.

TIA,

-- 

Kirby Vandivort                      Theoretical and Computational Biophysics 
Email: kvandivo@ks.uiuc.edu          3051 Beckman Institute
http://www.ks.uiuc.edu/~kvandivo/    University of Illinois
Phone: (217) 244-5711                405 N. Mathews Ave
Fax  : (217) 244-6078                Urbana, IL  61801, USA

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


Re: current best practices for time zones

Posted by Gareth Andrew <ga...@ntlworld.com>.
I don't think this is possible server-side since you can only determine 
the country the client is in from the request headers.  So I think you 
have to do something client-side ie. javascript.
To print server time using javascript- you probably want to do something 
like:
<SCRIPT>
now =new Date(<bean:write name="theTime"/>);
document.write(now.toLocaleString());
</SCRIPT>

where the bean "theTime" stores the date as a string containing 
milliseconds since the epoch.

see: 
http://devedge.netscape.com/library/manuals/2000/javascript/1.5/reference/date.html

Gareth

Kirby Vandivort wrote:

>Let's say I want to print the current time (or choose your favorite 
>time) from the server to the user's browser.
>
>Currently, I'm storing a Date object in appropriate scope, and when
>I get to the front end, I'm doing something similar to:
>
><bean:write name="theTime" property="dateObj" formatKey="format.time.date"/>
>
>where format.time.date is something like hh:mm:ssa'/'yyyy.MM.dd as an
>example.
>
>
>So, that's the background.  I was (naively, I suppose) expecting that
>struts would figure out where the user is coming from, similar to how
>it does language determination, and automatically convert the Date from
>the server's timezone to the user's browser's timezone.
>
>However, this is not happening.  All dates are getting printed in the
>server's timezone.
>
>Is there a relatively clean way to handle this?  Searching the archive
>returns a few hits from 2001 and I was wondering if there is anything
>new on this.  Am I going to have to end up creating Locales on the
>business end and managing everything there, or can I handle this
>presentation-side?
>
>Just curious what others that are a bit closer to the pulse of recent
>struts than I have chosen.
>
>TIA,
>
>  
>



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


Re: current best practices for time zones

Posted by Kris Schneider <kr...@dotech.com>.
Assuming you can create a scoped attribute of type String or java.util.TimeZone
called "timeZone", try JSTL:

<fmt:formatDate value="${date}"
                pattern="hh:mm:ssa/yyyy.MM.dd"
                timeZone="${timeZone}"/>

Quoting Kirby Vandivort <kv...@ks.uiuc.edu>:

> Let's say I want to print the current time (or choose your favorite 
> time) from the server to the user's browser.
> 
> Currently, I'm storing a Date object in appropriate scope, and when
> I get to the front end, I'm doing something similar to:
> 
> <bean:write name="theTime" property="dateObj"
> formatKey="format.time.date"/>
> 
> where format.time.date is something like hh:mm:ssa'/'yyyy.MM.dd as an
> example.
> 
> 
> So, that's the background.  I was (naively, I suppose) expecting that
> struts would figure out where the user is coming from, similar to how
> it does language determination, and automatically convert the Date from
> the server's timezone to the user's browser's timezone.
> 
> However, this is not happening.  All dates are getting printed in the
> server's timezone.
> 
> Is there a relatively clean way to handle this?  Searching the archive
> returns a few hits from 2001 and I was wondering if there is anything
> new on this.  Am I going to have to end up creating Locales on the
> business end and managing everything there, or can I handle this
> presentation-side?
> 
> Just curious what others that are a bit closer to the pulse of recent
> struts than I have chosen.
> 
> TIA,
> 
> -- 
> 
> Kirby Vandivort                      Theoretical and Computational Biophysics
> 
> Email: kvandivo@ks.uiuc.edu          3051 Beckman Institute
> http://www.ks.uiuc.edu/~kvandivo/    University of Illinois
> Phone: (217) 244-5711                405 N. Mathews Ave
> Fax  : (217) 244-6078                Urbana, IL  61801, USA
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 


-- 
Kris Schneider <ma...@dotech.com>
D.O.Tech       <http://www.dotech.com/>

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


RE: current best practices for time zones

Posted by Andrew Hill <an...@gridnode.com>.
I had this requirement. There isnt (at least not to my knowledge) an easy or
clean way to handle this, and struts doesnt provide much to help with it.

Like you, my requirement was that time and date data in the app be shown in
the browsers timezone, which could be different from the server. I asked
this myself last year but didnt get much in the way of useful responses. Had
to spend a lot of time figuring out a 'least worst' solution.

I ended up adding a select box to the applications login page where the user
could select their timezone.
The default selection being the servers timezone, as its a fair bet that the
majority of the users will be in the same timezone as their server, as the
applications presentation tier is expected to be accessed more (but
certainly not exclusively) over intranets.

Java has several hundred inbuilt timezones to choose from - and timezones
are not the same as locales. For example Australia has many timezones, but
the locale is still just EN_au. (or is that AU_en?, or en_AU? or...
whatever...)

Client side JavaScript provides a method of determining the browsers
*current* offset from UTC (it changes depending on DST), so I had this value
submitted to the server and used it to narrow down the list of timezones
they can pick (remember you need to check against both normal and DST
offsets - as you dont know the DST rules of the browsers timezone), this
however doesnt narrow it down to one, but to around 10 to 20 - many of which
are just duplicates with different names.

(To further complicate matters my app has to be fully i18n-ed and the
localised timezone names arent much good for this (its hard to pick between
10 different options that all say "GMT+8") - so I actually have to have
suitable names for several hundred zones in my resources file!).

Just because a zone has the same UTC offset today as another zone, doesnt
mean they are close enough - as the DST rules may well vary - and the app
needs to show dates it recorded earlier properly - ie: based on the offset
on that date - not todays date, and if your displaying a verbose date with
the timezone indicated, you want it to be the correct timezone indicated
anyhow - (not an incorrect one that happens to have the same rules.)

Having spent days playing with this date stuff, I have to say that I am not
a big fan of the way dates, times, and timezones, and such like are handled
in the java api. Its a real mess... :-(

-----Original Message-----
From: Kirby Vandivort [mailto:kvandivo@ks.uiuc.edu]
Sent: Friday, 9 May 2003 00:49
To: struts-user@jakarta.apache.org
Subject: current best practices for time zones


Let's say I want to print the current time (or choose your favorite
time) from the server to the user's browser.

Currently, I'm storing a Date object in appropriate scope, and when
I get to the front end, I'm doing something similar to:

<bean:write name="theTime" property="dateObj" formatKey="format.time.date"/>

where format.time.date is something like hh:mm:ssa'/'yyyy.MM.dd as an
example.


So, that's the background.  I was (naively, I suppose) expecting that
struts would figure out where the user is coming from, similar to how
it does language determination, and automatically convert the Date from
the server's timezone to the user's browser's timezone.

However, this is not happening.  All dates are getting printed in the
server's timezone.

Is there a relatively clean way to handle this?  Searching the archive
returns a few hits from 2001 and I was wondering if there is anything
new on this.  Am I going to have to end up creating Locales on the
business end and managing everything there, or can I handle this
presentation-side?

Just curious what others that are a bit closer to the pulse of recent
struts than I have chosen.

TIA,

--

Kirby Vandivort                      Theoretical and Computational
Biophysics
Email: kvandivo@ks.uiuc.edu          3051 Beckman Institute
http://www.ks.uiuc.edu/~kvandivo/    University of Illinois
Phone: (217) 244-5711                405 N. Mathews Ave
Fax  : (217) 244-6078                Urbana, IL  61801, USA

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


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