Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Timestamps using timezones

 
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?
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • 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.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic