-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Which Java API class for date type data with time zone?
PostPosted: Sat Apr 08, 2006 7:24 pm 
Regular
Regular

Joined: Wed Aug 25, 2004 7:40 pm
Posts: 65
In this web application, I am currently using the GregorianCalendar class to store a date data. The time zone is set based on the user's location. A date data is not stored corrently in the DB thorough Hibernate. For instance, the date "Sat Apr 08 11:56:38 PDT 2006" with "GMT+08" is saved as "2006-04-07 20:56:38.609-07". It seems the DB always takes the server time zone regardless of the time zone in Calendar data. Someone suggests that I only need the Date and the DateFormat data types instead. I am not sure that I have to do such data formating during the date date saving and retrieving processes.

What is a right way in this regard?

Thanks for your inputs.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 09, 2006 11:32 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
That's because dates are handled as integer values measured from an epoch (1 Jan 1970 for Java, varies for DBs: it's some time in 1753 for SQLServer :). Your options are to always convert all times to DB timezone before you save them, or to save the timezone as a separate value. There is no built-in feature that does this for you.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 10, 2006 1:27 am 
Regular
Regular

Joined: Wed Aug 25, 2004 7:40 pm
Posts: 65
tenwit wrote:
That's because dates are handled as integer values measured from an epoch (1 Jan 1970 for Java, varies for DBs: it's some time in 1753 for SQLServer :). Your options are to always convert all times to DB timezone before you save them, or to save the timezone as a separate value. There is no built-in feature that does this for you.


So, if I want to have user's TZ preserved, I have to have a TZ column.


Thanks for your information.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.