3

I am using GWT/Hibernate. i have a form created using GWT. it has one date field where user can select a date and one drop down where all timezones are displayed. now user selects date and timezone from dropdown. on click of save button i need to save date and timezone information. Also if server is configured in GMT, if user has selected any other timezone then it should be saved as user selected timezone information. when i try to query the same then it should return me the date with user selected timezone. Please suggest me what is the best way to implement it? should i have date and timezone columns in db separately? in which format do i need to save timezone information? Please help me.

Thanks!

user1016403
  • 12,151
  • 35
  • 108
  • 137
  • Does http://stackoverflow.com/questions/2532729/daylight-saving-time-and-timezone-best-practices provide any help? – mmmmmm Jan 09 '12 at 14:40
  • take a look at this [tutorial](http://www.sjhannah.com/blog/?p=113) and you'll have a better understanding. – Matt K Jan 09 '12 at 14:41

1 Answers1

4

Some databases have types that include timezone information (e.g. Oracle has TIMESTAMP WITH TIME ZONE). Use those if possible. Otherwise, save all dates in GMT and the timezone separately.

As for the format of the timezone, it's best to use the IDs from the tz database, which Java's timezone IDs are based on, e.g. "America/New_York" or "Europe/London". These IDs uniquely identify (unlike the three-letter timezone names which often have multiple meanings) an administrative timezone and its history (including DST intriduction/abolition and changes) - all of which can be necessary to correctly interpret a date.

Michael Borgwardt
  • 342,105
  • 78
  • 482
  • 720