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?...

Thanks
                LR
LVL 1
lfrodriguesAsked:
Who is Participating?
 
LischkeCommented:
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
0
 
LischkeCommented:
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;

var
  FileTime: TFileTime;
  SystemTime: TSystemTime;
  I: Int64;
 
begin
  // 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);
end;


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
0
 
lfrodriguesAuthor Commented:
I've post a deletion request on the other question. Thanks
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
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.
0
 
LischkeCommented:
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
0
 
lfrodriguesAuthor Commented:
I would like to use use source insstead of using the windows funtion: FileTimeToSystemTime
0
 
LischkeCommented:
Please, what source? What should that be? Can you please be a bit more specific?
0
 
lfrodriguesAuthor Commented:
the source of FileTimeToSystemTime
0
 
lfrodriguesAuthor Commented:
it works so thanks
0
 
LischkeCommented:
C grading, mmh?
0
 
lfrodriguesAuthor Commented:
ups it was supost be b sorry...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.