文件时间var
hf: THandle;
tC, tA, tW: TFileTime;
sC, sA, sW: TSystemTime;
begin
hf := CreateFile('d:\1.bmp', GENERIC_READ, 0, nil, OPEN_EXISTING, 0, 0);
getfiletime(hf, @tC, @tA, @tW);
CloseHandle(hf);
FileTimeToSystemTime(tC, sC);
FileTimeToSystemTime(tA, sA);
FileTimeToSystemTime(tW, sW);
showmessage(inttostr(sC.wYear) + ':' + inttostr(sc.wMonth) + ':' + inttostr(sc.wDay) + #13 +
inttostr(sA.wYear) + ':' + inttostr(sA.wMonth) + ':' + inttostr(sA.wDay) + #13 +
inttostr(sW.wYear) + ':' + inttostr(sW.wMonth) + ':' + inttostr(sW.wDay));
系统时间 参见上面
hf: THandle;
tC, tA, tW: TFileTime;
sC, sA, sW: TSystemTime;
begin
hf := CreateFile('d:\1.bmp', GENERIC_READ, 0, nil, OPEN_EXISTING, 0, 0);
getfiletime(hf, @tC, @tA, @tW);
CloseHandle(hf);
FileTimeToSystemTime(tC, sC);
FileTimeToSystemTime(tA, sA);
FileTimeToSystemTime(tW, sW);
showmessage(inttostr(sC.wYear) + ':' + inttostr(sc.wMonth) + ':' + inttostr(sc.wDay) + #13 +
inttostr(sA.wYear) + ':' + inttostr(sA.wMonth) + ':' + inttostr(sA.wDay) + #13 +
inttostr(sW.wYear) + ':' + inttostr(sW.wMonth) + ':' + inttostr(sW.wDay));
系统时间 参见上面
LocalTime:TSystemTime; //本地系统时间变量
FileTime_Creat:TFileTime; //文件建立时间
FileTime_LastAccess:TFileTime; //最后一次访问时间
FileTime_LastWrite:TFileTime; //最后一次更改时间
LsTime:TDateTime; //临时时间变量
pofFile:THandle; //文件句柄
begin
GetlocalTime(LocalTime);
LsTime:=SystemTimeToDateTime(LocalTime);
Label2.Caption:='本地时间:'+DateToStr(LsTime)+' '+TimeToStr(LsTime);pofFile:=CreateFile('c:\winzip.log', GENERIC_READ, 0, nil, OPEN_EXISTING, 0, 0);
GetFileTime(pofFile,@FileTime_Creat,@FileTime_LastAccess,@FileTime_LastWrite);
CloseHandle(pofFile);
FILE_CREATE_TIME=0;
FILE_Modify_Time=1;
......
function GetFileLastAccessTime(sFileName:string;uFlag:byte):TDateTime;
var
ffd:TWin32FindData;
dft:DWord;
lft:TFileTime;
h:THandle;
begin
h:=FindFirstFile(PChar(sFileName),ffd);
if h<>INVALID_HANDLE_VALUE then
begin
case uFlag of
FILE_CREATE_TIME:FileTimeToLocalFileTime(ffd.ftCreationTime,lft);
FILE_MODIFY_TIME:FileTimeToLocalFileTime(ffd.ftLastWriteTime,lft);
FILE_ACCESS_TIME:FileTimeToLocalFileTime(ffd.ftLastAccessTime,lft);
else
FileTimeToLocalFileTime(ffd.ftLastAccessTime,lft);
end;
FileTimeToDosDateTime(lft,LongRec(dft).Hi,LongRec(dft).Lo);
Result:=FileDateToDateTime(dft);
windows.FindClose(h);
end
else
result:=0;
end;
看哪一句后显示的不是 0;即是这一句有错
showmessage(inttostr(GetLasterror)); getlasterror=32GetFileTime(pofFile,@FileTime_Creat,@FileTime_LastAccess,@FileTime_LastWrite);
showmessage(inttostr(GetLasterror)); getlasterror=6CloseHandle(pofFile);
showmessage(inttostr(GetLasterror)); getlasterror=6
32L ERROR_SHARING_VIOLATION; 文件共享错误
6L ERROR_INVALID_HANDLE ; 没打开文件自然句柄无效CreateFile第三个参数设为 FILE_SHARE_READ 试试