File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Convert date time to file date time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Convert date time to file date time" Watch "Convert date time to file date time" New topic

Convert date time to file date time

sam patel
Ranch Hand

Joined: Jun 13, 2002
Posts: 103
I have standard delphi function which conver datetime to filedatetime here is the description
function DateTimeToFileDate(DateTime: TDateTime): Integer;
Use DateTimeToFileDate to convert a TDateTime value, which is the representation of date-and-time values used by the VCL, to a DOS date-and-time value.
For example, use DateTimeToFileDate to convert a TDateTime value to a
format that can be used as the Age parameter of FileSetDate. You may
also need to use DateTimeToFileDate to convert a TDateTime so that it
is compatible with the Time field of the TSearchRec record used by the FindFirst
and FindNext functions.
Lo returns the low-order Byte of the argument X as an unsigned value. X is an expression of type Integer.
Use Hi to obtain the high-order byte of an expression of type Word or Integer.
Note: Hi treats Integer as a 16-bit value, even if it is 32-bit.
This is the delphi code that convert the date

LongRec(Result).Lo := (Sec shr 1) or (Min shl 5) or (Hour shl 11);
LongRec(Result).Hi := Day or (Month shl 5) or ((Year - 1980) shl 9);

output Result is --> 784100796
Any help will be highly appreciated.
Carl Trusiak

Joined: Jun 13, 2000
Posts: 3340
Sounds like you have a good handle on the requirements. If you look what is going on, you break the date into it's field elements. A good canidate for this portion would be Calendar. Then these values are shifted by the amounts lists, the results ored together and the High shifted and ored to the low.
I took a quick stab at this and here is the code I came up with:

To better understand bit operations in Java, Read Cat and Mouse Game with Bits

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
I agree. Here's the link:
subject: Convert date time to file date time
It's not a secret anymore!