使用函数:
System.IOUtils.TDirectory.GetCreationTime//获取创建时间
System.IOUtils.TDirectory.SetCreationTime//设置创建时间
注:UTC结尾的返回 <Coordinated Universal Time即协调世界时>。
示例:
代码
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.FileCtrl, System.IOUtils; type TForm1 = class(TForm) Button_GetCreateTime: TButton; Button_SetCreateTime: TButton; Edit_Time: TEdit; Button_ChooseFolder: TButton; Label_Path: TLabel; Memo1: TMemo; procedure Button_ChooseFolderClick(Sender: TObject); procedure Button_GetCreateTimeClick(Sender: TObject); procedure Button_SetCreateTimeClick(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} var sDir: string; procedure TForm1.Button_ChooseFolderClick(Sender: TObject); begin if not SelectDirectory('请选择一个文件夹', 'H:', sDir) then Exit; Label_Path.Caption := sDir; Button_SetCreateTime.Enabled := True; Button_GetCreateTime.Enabled := True; end; procedure TForm1.Button_GetCreateTimeClick(Sender: TObject); var CTime: TDateTime; begin // try CTime := TDirectory.GetCreationTime(Label_Path.Caption); Edit_Time.Text := DateTimeToStr(CTime); except on e: Exception do begin MessageDlg('获取失败!' + e.Message, mtError, [mbok], 0); Exit; end; end; end; procedure TForm1.Button_SetCreateTimeClick(Sender: TObject); begin try TDirectory.SetCreationTime(Label_Path.Caption, StrToDateTime(Edit_Time.Text)); except on e1: Exception do begin MessageDlg('设置失败!' + e1.Message, mtError, [mbok], 0); Exit; end; end; end; end.