This reflects how javascript and browsers handle date/time rather than GWT.
Both a java Date and a javascript date represent an instant in time rather than a particular day/month/year/hour/minute, and they do this by storing the number of milliseconds since Jan 1 1970 (ie no timezone information, just a numer of milliseconds). Whenever a date is displayed by javascript, it uses the local timezone to interpret the value and work out what they day/month/year/hour etc is. Conversely, if you create a date/time on the browser, the browser will use the timezone to work out the number of milliseconds since 1970 it represents, and this is what goes across the wire in GWT RPC. If you look at the value of date.getTime() on server and client, you should see that that value does not change as dates are transferred. If you want to represent a particular day/month/year/hour/minute, then you'll have to send these values separately over RPC and rebuild the date on either side. Paul javaunixsolaris wrote: > GWT RPC manipulates my date objects and I can't predict how. > > I develop on a machine in located in timezone MST. > - > $ date > Fri Apr 2 16:18:59 MDT 2010 > - > When I debug through com.google.gwt.dev.DevMode (the Jetty popup / > browser with plugin) the date objects are NOT manipulated between my > browser and the server. For instance if I send the Date object: > "1/1/2011 9:30AM" it appears the same in the database (local): > mysql> select startTime from RESERVATION; > +---------------------+ > | startTime | > +---------------------+ > | 2011-01-01 09:30:00 | > +---------------------+ > While developing that's how I want it to behave, but once deployed on > a separate server I run into trouble: > > The server where I deploy the application is located in timezone EST. > - > $ date > Fri Apr 2 18:19:03 EDT 2010 > - > Using my browser located in an MST timezone my date objects are > manipulated seven hours! I could have expected 2 hours because that's > the difference from MST to EST but why seven? (see UTC idea below) > For example when my web browser sends Date object: "1/1/2011 9:30AM" > here's what ends up in the database (located on EST server): > mysql> select startTime from RESERVATION; > +---------------------+ > | startTime | > +---------------------+ > | 2011-01-01 16:30:00 | > +---------------------+ > So GWT RPC is adding seven hours (retrieving from the database to the > browser will minus seven hours). > > So my theory now is that GWT is converting it to UTC for me (which is > 7 hours from MST) when putting into the database and converting from > UTC to MST when retrieving from the database to the browser. But why > then won't it behave the same way in DevMode? This makes developing > the application difficult. Not to mention since GWT is manipulating > my Date objects can I trust GWT to observe Daylight Savings Time > correctly every year? > > -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
