• 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
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

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.
 
Surfs up space ponies, I'm making gravy without this lumpy, tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!