Avatar billede fredand Forsker
19. maj 2008 - 14:41 Der er 4 kommentarer og
1 løsning

Why does my dates differ?

Hello!

I got a strange problem that I hope I could get your excellent input about.

I receive a message from a mq-server.
I write to a database the JmsTimeStamp of the message as an long.
The JmsTimeStamp is = 1211183534650

To see this JmsTimeStamp in a better "readable" way I tried this in my Eclipse Scrapbook as:
System.out.println(new java.util.Date(1211183534650L));
This gave me:
Mon May 19 09:52:14 CEST 2008

But if I did this in my oracle:
select MESSAGE_ID, ( TO_DATE('01/01/1970', 'DD/MM/YYYY')  + MESSAGE_TIMESTAMP/(24*60*60*1000)) as DATUM from MYLOG_MESSAGE_LOG order by DATUM DESC

Or the same with the long from the database:
select ( TO_DATE('01/01/1970', 'DD/MM/YYYY')  + 1211183534650/(24*60*60*1000)) as DATUM from MYLOG_MESSAGE_LOG order by DATUM DESC

I get this:
2008-05-19 07:52:15

It differs 2 hour and 1 second????

To me the code looks ok, but somewhere 2 hours is missing.

Best regards
Fredrik
Avatar billede pidgeot Nybegynder
19. maj 2008 - 14:48 #1
The 2 hours could very well be due to the timezone. Notice that the first one is shown in CEST (Central European Summer Time, UTC+2). If the other is in UTC, that would explain it.

As far as the 1 second is concerned, I'm not sure.
Avatar billede fredand Forsker
19. maj 2008 - 15:02 #2
I bet you solved it!!!

Please give an answer so I can reward you!

Best regards
Fredrik
Avatar billede pidgeot Nybegynder
19. maj 2008 - 15:16 #3
Here you are.

Come to think of it, the difference of 1 second may be due to rounding. If JmsTimeStamp rounds down (so the .65 seconds is ignored), but Oracle rounds "regularly" (rouding off .65 to 1), that would explain it. (JmsTimeStamp would be more accurate, IMO)
Avatar billede fredand Forsker
19. maj 2008 - 15:38 #4
Thanks alot mate!

Your last thougts will probably solve the missing second as well!

Best regards
Fredrik
Avatar billede pidgeot Nybegynder
19. maj 2008 - 15:40 #5
A simple way to test it would of course be to use 1211183534350 instead and see if the seconds match up  - but you may already have guessed that.

There is, of course, the possibility that Oracle always rounds UP, in which case 1211183534000 should give the desired result (though I doubt this is the case).
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester