• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Timestamps using timezones

 
Anthony Smith
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a timestamp format liek the following passed to me to add to a database: 20080203171600Z-0400

I had a hard time trying to put this in Oracle, but I finally figured it out:

INSERT INTO test_timestamp VALUES
(TO_TIMESTAMP_TZ(REPLACE ('20050203171600Z-0400','Z',' '),'yyyymmddhh24miss TZHTZM'));

test_timestamp has a column with type: TIMESTAMP(0) WITH TIME ZONE


When I retrive this from a resultset, I use the getTimestamp("TEST_TMSTP");


When I use the same date using SimpleDateFormat and call getTime on both, I get different values... Why is that?

SimpleDateFormat fmtTimestamp = new SimpleDateFormat ("yyyyMMddHHmmssZ");
fmtTimestamp.parse(timestamp.replaceAll("Z", ""));

getTimestamp("TEST_TMSTP") = 1107472560000
fmtTimestamp.parse(timestamp.replaceAll("Z", "")) = 1107465360000

Why are these numbers not the same?
 
Anthony Smith
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh disregard the one that says 2008...

I used this one on both attempts:
20050203171600Z-0400
 
Anthony Smith
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone?
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anthony,
I'm only guessing, but it's probably due to the way "SimpleDateFormat" works. Perhaps this article will help:

http://www.javaworld.com/javaworld/jw-10-2003/jw-1003-time.html

Good Luck,
Avi.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic