D
DZHZH2000
Unregistered / Unconfirmed
GUEST, unregistred user!
从以前的帖子里翻来的。我发现当时间的毫秒是奇数是总是设成小一毫秒的偶数。<br>如:<br>SetFileDateTime('aaa.txt',fttLastWrite,StrToDateTime('2003-1-1 13:32:21:13'))<br>结果是2003-1-1 13:32:21:12<br>而毫秒是偶数则结果正确。<br><br>function SetFileDateTime(const FileName: string; FileTimeType: TFileTimeType; DateTime: TDateTime): Integer;<br>var<br> Handle: THandle;<br> LocalFileTime, FileTime: TFileTime;<br> DosDateTime: Integer;<br> I: TFileTimeType;<br> FileTimes: array[TFileTimeType] of Pointer;<br>begin<br> Result := 0;<br> DosDateTime := DateTimeToFileDate(DateTime);<br> Handle := FileOpen(FileName, fmOpenWrite or fmShareDenyNone);<br> if Handle <> INVALID_HANDLE_VALUE then<br> try<br> for I := fttCreation to fttLastWrite do FileTimes := nil;<br> DosDateTimeToFileTime(LongRec(DosDateTime).Hi, LongRec(DosDateTime).Lo, LocalFileTime);<br> LocalFileTimeToFileTime(LocalFileTime, FileTime);<br> FileTimes[FileTimeType] := @FileTime;<br> if SetFileTime(Handle, FileTimes[fttCreation], FileTimes[fttLastAccess],<br> FileTimes[fttLastWrite]) then Exit;<br> finally<br> FileClose(Handle);<br> end;<br> Result := GetLastError;<br>end;<br>