Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > About ResultSet.getTimeStamp

Reply
Thread Tools

About ResultSet.getTimeStamp

 
 
RAMK
Guest
Posts: n/a
 
      02-15-2005
hi,
If I execute ResultSet.getTimeStamp(columnName), where columnName
is of type "DATE" in the database.
Now if construct the java Date object like Date date = new
Date(timestamp.getTime()), where 'timestamp' is returned by
getTimeStamp().

Are there any timezone conversions while retrieving DATE datatypes
from the database. I read somewhere that by default it is converted to
JVM time zone. I guess if the jdbc driver does any conversion, then
does it take the value in Date datatype to be in server time zone( DB
timezone) before any conversions to JVM time zone?

Much appreciated...

 
Reply With Quote
 
 
 
 
Anton Spaans
Guest
Posts: n/a
 
      02-15-2005

"RAMK" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> hi,
> If I execute ResultSet.getTimeStamp(columnName), where columnName
> is of type "DATE" in the database.
> Now if construct the java Date object like Date date = new
> Date(timestamp.getTime()), where 'timestamp' is returned by
> getTimeStamp().
>
> Are there any timezone conversions while retrieving DATE datatypes
> from the database. I read somewhere that by default it is converted to
> JVM time zone. I guess if the jdbc driver does any conversion, then
> does it take the value in Date datatype to be in server time zone( DB
> timezone) before any conversions to JVM time zone?
>
> Much appreciated...
>


The returned timestamp is a point in time, regardless of timezone
(regardless of where you are on earth). It is up to the programmer to add a
timezone (relate the point in time to a specific place on earth). This will
then give you the *time-of-day* in the specified timezone:

Example:
Code:
Date date = new Date(timestamp.getTime());
String formatPattern = ....;
// sdf contains a Calendar object with the default JVM/system timezone.
SimpleDateFormat sdf = new SimpleDateFormat(formatPattern);

TimeZone T1;
TimeZone T2;
.... // obtain values for T1 and T2 somehow...
....
....
// set the Calendar of sdf to timezone T1
sdf.setTimeZone(T1);
System.out.println(sdf.format(date));

// set the Calendar of sdf to timezone T2
sdf.setTimeZone(T2);
System.out.println(sdf.format(date));

// Use the 'calOfT2' instance-methods to get specific info
// about the time-of-day for date 'date' in timezone T2.
Calendar calOfT2 = sdf.getCalendar();
.... // do stuff with calOfT2
....

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments