I have a server-equipment configuration where I need to change the equip date config, using UDP. The server is written in Java and the equipment, in Delphi.
So, the flow of the data is this:
Java server (Java date) -> UDP (integer date) -> Delphi equipment (Delphi date)
The problem is that when I pass the date as an integer, java calculates miliseconds from 1970, and Delphi, seconds. I pass then the date as following: today.getTime() / 1000, but the equipment understands this as a 2008 date, when we’re on 2012.
I can change the Java code, but the equipment is 3rd party and I don’t have access to it’s source code.
There’s difference between Java and Delphi date parsing that allow this discrepancy?
EDIT:
Thanks to MДΓΓ БДLL I noticed I was multiplying by 1000 instead of dividing by it, I now have a better date, but still wrong (was somewhen in 2033, now it’s in 2008).
A Unix time stamp is the same as the one used in Java. Delphi’s TDateTime, on the other hand, is based on a starting date of 12:01 AM on 12/30/1899 (it’s a COM compatibility thing), so some conversion is necessary. These functions will do it; I’ve also added a quick piece of test code to show the conversion works correctly both ways.