-->
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.  [ 2 posts ] 
Author Message
 Post subject: TimestampType .. converts to localtime right?
PostPosted: Mon Mar 31, 2008 7:52 pm 
Newbie

Joined: Tue Nov 25, 2003 11:49 pm
Posts: 12
So,

if the default timezone for my vm is say CST

and I parse a date that's in GMT using a SimpleDateFormat 'z' and get a Date object. That gives me a Date ie. timestamp.

If I want to store that via TimestampType to the database will it store the time in local/default timezone and not GMT?

Do I have to write my own CustomType if I do not wish it to store the time as a local time?

If I want to store the time as UTC do I have to use a Calendar in the user defined type that converts the Date to UTC?


Top
 Profile  
 
 Post subject: Time Zone Fun
PostPosted: Wed Apr 02, 2008 12:40 pm 
Newbie

Joined: Tue Apr 01, 2008 9:14 am
Posts: 3
I have just been wading through this issue myself. And while I can't answer all of your questions, I may help you avoid a couple potential pitfalls.

First, the way the database stores time zones is somewhat dependent on the database you are using. So be sure to check your documentation.

Second, many database have different data types for storing a time. I know in Oracle and PostgreSQL they both have something like:

timestamp with time zone
timestamp without time zone

For an explanation and sample code, check out this slightly old but useful Oracle discussion:
http://www.databasejournal.com/features/oracle/article.php/3072991


So what to do? The best that I have come up with is the following:
1. Set your database to believe it is in GMT time zone (Time zone 0)
2. Use the data column type timestamp without time zone
3. Use code in your front end to convert to/from GMT when messing with the database. At this point, the time zone conversion just becomes a display issue.

Hope this helps and points you in the right direction.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.