19. maj 2008 - 14:41Der 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.
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.
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)
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).
Synes godt om
Ny brugerNybegynder
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.