About ResultSet.getTimeStamp

Discussion in 'Java' started by RAMK, Feb 15, 2005.

  1. RAMK

    RAMK Guest

    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...
    RAMK, Feb 15, 2005
    #1
    1. Advertising

  2. RAMK

    Anton Spaans Guest

    "RAMK" <> wrote in message
    news:...
    > 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
    ....
    
    Anton Spaans, Feb 15, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matrix
    Replies:
    0
    Views:
    558
    Matrix
    Apr 1, 2004
  2. matrix ¿ìÀÖÄñ

    How i know the size of "resultset"?

    matrix ¿ìÀÖÄñ, Apr 3, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    3,413
    matrix ¿ìÀÖÄñ
    Apr 3, 2004
  3. =?Utf-8?B?VGltX2s=?=

    Web Treeview loaded from resultset example

    =?Utf-8?B?VGltX2s=?=, Jun 18, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    327
    =?Utf-8?B?VGltX2s=?=
    Jun 18, 2004
  4. =?Utf-8?B?VGltX2s=?=

    Web Treeview loaded from resultset example

    =?Utf-8?B?VGltX2s=?=, Jun 18, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    248
    =?Utf-8?B?VGltX2s=?=
    Jun 18, 2004
  5. RAMK

    ResultSet.getTimeStamp()

    RAMK, Mar 22, 2005, in forum: Java
    Replies:
    2
    Views:
    8,234
    Lee Fesperman
    Mar 22, 2005
Loading...

Share This Page