how to convert UNIX time to DOS time

I need to convert a unix time to dos. I do i do this?
The code must support when february is 29 days long and make the write ajustements.

So any ideas?...

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You have posted this question twice! I'd recomend that you delete quickly the other one.

The solution for your problem is:

function UnixTimeToDateTime(const UnixTime: Integer): TDateTime;

  FileTime: TFileTime;
  SystemTime: TSystemTime;
  I: Int64;
  // first convert unix time to a Win32 file time
  I := Int64(UnixTime) * Int64(10000000) + 116444736000000000;
  FileTime.dwLowDateTime := DWORD(I);
  FileTime.dwHighDateTime := I shr 32;

  // now convert to system time
  FileTimeToSystemTime(FileTime, SystemTime);

  // and finally convert the system time to TDateTime
  Result := SystemTimeToDateTime(SystemTime);

I must admit, I never checked it for the 29. February issue, so this needs to be verified. Therefor I post this as comment only.

Ciao, Mike
lfrodriguesAuthor Commented:
I've post a deletion request on the other question. Thanks
lfrodriguesAuthor Commented:
I've tested that source and it works iven if february is 29 days. How do i reverse the process??
Yor source is pretty good but i have  has some problems implementing it, since my final componet might be compiled with delphi 1 or 2 and they don't have int64. I would also preffer to use a function with has the source instead of using FileTimeToSystemTime.
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Well, to reverse the calculation simply reverse the steps I gave you in the routine above. Is this so hard to do it yourself or do you expect that I give you every single code line ready to build in into your program?

Concerning Delphi 1/2 compatibility: Unfortunately, I can neither write nor test code for these versions as I don't have them. That's stuff you need to do yourself. And what do you mean with: "I would also preffer to use a function with has the source instead of using FileTimeToSystemTime." I have not understood this sentence.

Ciao, Mike
lfrodriguesAuthor Commented:
I would like to use use source insstead of using the windows funtion: FileTimeToSystemTime
Please, what source? What should that be? Can you please be a bit more specific?
lfrodriguesAuthor Commented:
the source of FileTimeToSystemTime
The algorithm works as I wrote it here. There's no other way unless you want to write the stuff which the system function FileTimeToSystemTime and SystemTimeToDateTime implement yourself. This does not make any sense. So take it as it is or leave it.

Ciao, Mike

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lfrodriguesAuthor Commented:
it works so thanks
C grading, mmh?
lfrodriguesAuthor Commented:
ups it was supost be b sorry...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.