procedure TForm1.Button1Click(Sender: TObject);//获取文件创建时间 var FileName: string; ti: Integer; dt: TDateTime; begin FileName := 'D:\test\Test.txt'; ti := FileAge(FileName); ShowMessage(IntToStr(ti)); //返回: 1030115371, 需要转换 dt := FileDateToDateTime(ti); //转换 ShowMessage(DateTimeToStr(dt)); //2010-11-6 10:01:22 end; procedure TForm1.Button2Click(Sender: TObject);//获取文件最后修改时间 procedure DirectoryDateTimeInfo(const path : string) ; var sr : TSearchRec; modifiedTime : TDateTime; // 修改时间 begin if sysUtils.FindFirst(path, faDirectory, sr) = 0 then modifiedTime := FileDateToDateTime(sr.Time) ; // 修改时间 ShowMessage(Format('Last Modified Time: "%s"', [DateTimeToStr(modifiedTime)])) ; FindClose(sr) ; end; begin DirectoryDateTimeInfo('D:\test\Test.txt'); end;
标签:begin,modifiedTime,文件创建,sr,Delphi,时间,ti,ShowMessage From: https://www.cnblogs.com/yoooos/p/17642843.html