apigee, a better way to API!
rohits: I have an DB where I store information in timestamp format without timezone.
rohits: So suppose if now I am getting Apr 4 2008 7:00 from the DB into a java.util.Date variable, the java.util.Date by itself will append EST as my application server is in EST but I want to append GMT to it somehow. Like I want Apr 4 2008 7:00 GMT and not Apr 4 2008 7:00 EST.
apigee, a better way to API!
luck, db
There are no new questions, but there may be new answers.
Kiran Dalvi wrote:You are absolutely correct. java.util.Date does not have a Time Zone associated with it.
The issue here was when printing toString() on a Date object, it does show a TimeZone (Of an AppServer/Local Machine) and we needed to change that displayed value as well.
luck, db
There are no new questions, but there may be new answers.
Kiran Dalvi wrote: I want the Date object to contain UTC time.
Kiran Dalvi wrote:Thanks for the reply. I am trying to fulfill 2 requirements -
1. Whenever I display date+time on my site, it should be UTC.
2. All calculations on the Date+Time should happen on UTC alongwith DB persistance.
3. My AppServer runs in India (UTC+5.5)
With your solution, I can achieve (1) but can't possibly achieve(2).
luck, db
There are no new questions, but there may be new answers.
Darryl Burke wrote:
Kiran Dalvi wrote:Thanks for the reply. I am trying to fulfill 2 requirements -
1. Whenever I display date+time on my site, it should be UTC.
2. All calculations on the Date+Time should happen on UTC alongwith DB persistance.
3. My AppServer runs in India (UTC+5.5)
With your solution, I can achieve (1) but can't possibly achieve(2).
The long value internally stored by a Date instance doesn't get changed by setting the default TimeZone. It doesn't depend on the TimeZone at all, only on the number od milliseconds since the Epoch.
The Epoch was the same instant of time everywhere.
Kiran Dalvi wrote:Thanks. Much more clear now.
Looks like changing JVM TimeZone suits the best to what I am looking for.
Jeff Verdegan wrote:
Now, depending on how your database handles times, you may instead need setTimestamp(int parameterIndex, Timestamp x, Calendar cal) and the corresponding getTimestamp(String columnLabel, Calendar cal). If I recall correctly, I've seen some inconsistencies and non-intuitive behaviors across different DBs' handling of times, but one of these method pairs should be all you need. You'll just have to do some testing with different combinations to make sure you get what you expect.
Thank you my well lotioned goddess! Here, have my favorite tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|