About ResultSet.getTimeStamp

R

RAMK

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...
 
A

Anton Spaans

RAMK said:
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
....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top