• Post Reply Bookmark Topic Watch Topic
  • New Topic

TimeStamp - changed by my DB?  RSS feed

 
adam oczos
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi everybody;
i have a simple problem using date fileds in java+DBs. there's a client and a server (OC4J + 8i DB). the client sends a point in time
as a number of seconds from 1970.
on the server i read it, multiply by 1000 and pass it to the DB, into DATE field.
a sample:
// reading seconds + conversion
Long seconds = new Long(sub);
Timestamp ts = new Timestamp((seconds.longValue() * 1000));
// set it in a query
DBquery.setTimestamp(j + 1, ts);
// ... adn later execute a query
everything is fine, but... but the date is NOT what was sent from the client. it's shifted. depending on the country
the system runs, it there's a constant difference between the what should be stored in the DB and what is really written there.
that leads to the conclusion that it's related to time-zones. the difference comes probably from the gap between GMT and local time.
anything i can do about it? for example: how to use TimeZone to format the timestamp properly (if possible).
thanx a lot for any help.
.adam
 
Tom Blough
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adam,
My guess is that the problem is a time zone issue. The client code is probably adding the time zone offset to the current time before converting it to seconds.
 
adam oczos
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tom.
Thnak you for your answer, but it looks like it's the server. Somehow...
Example:
- let's assume that 1000 means 2003-11-11 12:00:00
- i take 1000, multiply it and what i can se in DB is 2003-11-11 13:30:00
- when i want to conver the DB date to long, it may be 1015. not 1000.
what am i doing wrong here? clients and servers are in the same time zone.
thank you.
 
adam oczos
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and the solution can be like:
Long aa = new Long(sub);
Timestamp bb = new Timestamp((aa.longValue() * 1000));
long offset = new java.util.Date().getTimezoneOffset() * 60000;
Timestamp cc = new Timestamp(bb.getTime() + offset);
thanx anyway
.adam
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!