• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Convert date time to file date time

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic