Some functions will return a TFileTime type (_FILETIME structure in WinAPI) such as GetProcessTimes(), GetThreadTimes(), GetFileTime(), etc. This function will convert that value to a readable date/time string. Read the comment for the usage. You can change the format of the resulting date string in the FormatDateTime() function any way you please. Thanks to Phil Stubbington <http://www.ambitus.co.uk> for this code. If you want just the modified date of a file, see GetModifiedDate().
function FileTimeToLongStr(ft : TFileTime): string;
{ func to convert TFileTime to readable date/time. }
{ Thanks to Phil Stubbington for this code. }
{ Email: [email protected] Web: http://www.ambitus.co.uk }
(* Usage:
procedure TForm1.Button1Click(Sender: TObject);
var
fs: TFileStream;
CreateTime,
LastAccessTime,
WriteTime: TFileTime;
CreateTimeStr,
LastAccessTimeStr,
WriteTimeStr: string;
begin
fs := TFileStream.Create('C:\SomeDir\SomeFile.tmp', fmOpenRead or fmShareDenyNone);
try
GetFileTime(fs.Handle, @CreateTime, @LastAccessTime, @WriteTime);
CreateTimeStr := FileTimeToLongStr(CreateTime);
LastAccessTimeStr := FileTimeToLongStr(LastAccessTime);
WriteTimeStr := FileTimeToLongStr(WriteTime);
{ ... }
finally
fs.Destroy;
end;
end; *) var
st: TSystemTime;
begin { convert FileTime to local time zone } if FileTimeToLocalFileTime(ft, ft) then { convert to SystemTime } if FileTimeToSystemTime(ft, st) then { Convert to TDateTime }
Result := FormatDateTime('dd mmmm yyyy hh:mm:ss', SystemTimeToDateTime(st))
else
Result := ''
else
Result := '';
end;