Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Convert date time to file date time

 
sam patel
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have standard delphi function which conver datetime to filedatetime here is the description
function DateTimeToFileDate(DateTime: TDateTime): Integer;
Description
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
year=2003
month=5
day=28
sec=57
min=45
hr=13
msec=107

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.
Thanks.
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic