There are two issues here.
- Java is big endian and Delphi is little endian.
- The Java code writes the date as a 64 bit integer. The Delphi code reads a floating point
TDateTime
.
Assuming you are going to change the Delphi code rather than the Java code, here's what you would do to bring the two sides together:
- Find or write some helper utilities to deal with the endian issue. Convert from big endian to little endian as soon as you read the data.
- Read the date as a 64 bit integer. Then you need to work out what the Java epoch is and convert from milliseconds since the Java epoch into a Delphi
TDateTime
which measures days elapsed since the Delphi epoch.
Dealing with endianness is simple enough, albeit rather tiresome.
The time conversion is perhaps a little more involved. The key information is that the Java epoch is the same as the Unix epoch. So a function that converts Unix time to Delphi TDateTime
is all you need. Fortunately the Delphi RTL supplies the very function. It's in the DateUtils
unit and is named UnixToDateTime
. Note that UnixToDateTime
receives a Unix time measured in seconds so you'll need to divide your value in milliseconds by 1000
.
One other point that I would make is that the Java code writes the data out with no gaps between fields. But the Delphi code uses an aligned record. Now, since all the members are the same size, there is no padding in this case. But it's something to watch out for. If I were you I would not be using legacy Pascal I/O to read this. I'd use a binary reader class that operates in a similar way to your Java writer. And I'd use that reader to read in the fields one at a time.
There may be something to be gained from finding (or writing) a reader class that handles the endian conversion for you.