I work with a third party application. It ALWAYS assumes that dates are
stored in GMT timezone. I have to query external table where dates are
stored in EDT. When I query that table using application API, it
converts this date from assuming its in GMT(i.e. shows 4 hour early as
of 2nd June, 2006). I want to convert this date back to EDT (ironic).
That is add the GMT difference back in that date to compensate for the
false assumption the application API makes.
How can I do this using Java?
Thank you.
Regards
AZXML
Dag Sunde - 02 Jun 2006 21:25 GMT
> I work with a third party application. It ALWAYS assumes that dates
> are stored in GMT timezone. I have to query external table where
[quoted text clipped - 3 lines]
> EDT (ironic). That is add the GMT difference back in that date to
> compensate for the false assumption the application API makes.
Take a look at :
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Calendar.html
and its TimeZone attributes

Signature
Dag.
P.Hill - 03 Jun 2006 21:58 GMT
> I work with a third party application. It ALWAYS assumes that dates are
> stored in GMT timezone. I have to query external table where dates are
[quoted text clipped - 3 lines]
> That is add the GMT difference back in that date to compensate for the
> false assumption the application API makes.
Are there 2 or 3 environments here? I'm not sure if your new need is to
modify the application or write a new one.
But in either case consider ResultSet.getDate(..., Calendar);
Which says read the date column but convert it into a java.util.Date
using the Calendar algorithm, but most importantly the timezone provided
in the additional argument.
Also consider setting Timezone.setDefault(Timezone) which tells your
VM to always pretend to use a different default TZ whenever you need to
convert a java.util.Date (or any subclass) which is a binary value into
a formatted time.
In nearly all cases, if you adding binary millisecond values to a Date
you are doing it incorrectly. Typically you want to tell a
SimpleDateFormat just to use a different Calendar and/or TZ to convert
the Java.util.Date to a time in some timezone.
HTH,
-Paul