passing timezone from client (GWT) to server (Joda Time)
        Posted  
        
            by Caffeine Coma
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Caffeine Coma
        
        
        
        Published on 2010-04-27T21:57:23Z
        Indexed on 
            2010/04/27
            22:13 UTC
        
        
        Read the original article
        Hit count: 686
        
I'm using GWT on the client (browser) and Joda Time on the server. I'd like to perform some DB lookups bounded by the day (i.e. 00:00:00 until 23:59:59) that a request comes in, with the time boundaries based on the user's (i.e. browser) timezone.
So I have the GWT code do a new java.util.Date() to get the time of the request, and send that to the server.  Then I use Joda Time like so:
new DateTime(clientDate).toDateMidnight().toDateTime()
The trouble of course is that toDateMidnight(), in the absence of a specified TimeZone, will use the system's (i.e. the server's) TimeZone.  I've been trying to find a simple way to pass the TimeZone from the browser to the server without much luck.  In GWT I can get the GMT offset with:
DateTimeFormat.getFormat("Z").fmt(new Date())
which results in something like "-0400".  But Joda Time's DateTimeZone.forID() wants strings formatted like "America/New_York", or an integer argument of hours and minutes.  Of course I can parse "-0400" into -4 hours and 0 minutes, but I'm wondering if there is not a more straightforward way of doing this.
© Stack Overflow or respective owner