你好快呀
BOOL GetFileTime( HANDLE hFile, // identifies the file
LPFILETIME lpCreationTime, // address of creation time
LPFILETIME lpLastAccessTime, // address of last access time
LPFILETIME lpLastWriteTime // address of last write time
);var
h: thandle;
d1,d2,d3: tdatetime;
begin
h:=openfile('e:\hh.txt');
Getfiletime(h,d1,d2,d3)
//d1,d2,d3反回时间
end;
BOOL GetFileTime( HANDLE hFile, // identifies the file
LPFILETIME lpCreationTime, // address of creation time
LPFILETIME lpLastAccessTime, // address of last access time
LPFILETIME lpLastWriteTime // address of last write time
);var
h: thandle;
d1,d2,d3: tdatetime;
begin
h:=openfile('e:\hh.txt');
Getfiletime(h,d1,d2,d3)
//d1,d2,d3反回时间
end;
解决方案 »
- progressbar 进度条满了程序还没完
- 使用SHFileOperation进行文件拷贝,我屏蔽了它自带的Progressbar,想自己做个Progressbar,能给点思路吗?
- 可能你觉得不怪???
- 哪位高手能帮我讲这段c++程序转化为delphi吗??
- 在Delphi下如何Copy一个Access数据库及如何覆盖之?
- 控件注册问题?
- 老是弹出 cpu thread 窗口,高手指点一下吧。
- 为什么我import了flash的控件,但是在activex控件面板上没有发现这个控件?
- 我做了个chm帮助,如何调用呀?用什么函数?ShellExecute吗?
- 如何动态建立和添加二级子菜单??
- 求教有关网络编程方面的论文
- 在把焦点置于maskedit中时,怎样可以把焦点定位于maskedit的某一位置啊~~急
BOOL GetFileTime(
HANDLE hFile, // handle to file
LPFILETIME lpCreationTime, // 创建时间
LPFILETIME lpLastAccessTime, // 最后一次访问时间 lpLastWriteTime // 最后一次读
);
date and time values}
TDosTime=Record
Hour : Byte;
Minutes : Byte;
seconds : Byte;
end; TDosDate = Record
Year : Word;
Month : Byte;
Day : Byte;
end;var
Form1: TForm1;
hFile: THandle; // a handle to the opened fileimplementation{this function provides a convenient way to convert a Dos time into its component parts}
function ConvertDosTimeToSystemTime(FileDosTime: WORD): TDosTime;
var
DosTime: TDosTime;
begin
DosTime.Seconds := (FileDosTime and $1F) * 2;
DosTime.Minutes := (FileDosTime and $7E0) shr 5;
DosTime.Hour := (FileDosTime and $F800) shr 11;
Result := DosTime;
end;{this function provides a convenient way to convert a
Dos date into its component parts}function ConvertDosDateToSystemDate(FileDosDate: WORD): TDosDate;
var
DosDate: TDosDate;
begin
DosDate.Day := FileDosDate and $1F;
DosDate.Month := FileDosDate and $1E0 shr 5;
DosDate.Year := (FileDosDate and $FE00) shr 9 + 1980;
Result := DosDate;
end;procedure TForm1.SpeedButton2Click(Sender: TObject);
var
Security: TSecurityAttributes; // attributes for the opened file FileName: PChar; // holds the filename
WriteTime, LocalTime: TFILETIME; // holds file times
DosDate, DosTime: WORD; // holds the Dos date and time
infoDosTime: TDosTime; // holds Dos time information
infoDosDate: TDosDate; // holds Dos date information
SystemTime: TSystemTime; // holds the last modification timebegin
{setup the security attributes for the opened file}
Security.nLength := SizeOf(TSecurityAttributes);
Security.lpSecurityDescriptor := nil;
Security.bInheritHandle := FALSE; {display the open dialog box}
if OpenDialog1.Execute then
begin
{display the selected filename...}
FileName := PChar(OpenDialog1.FileName);
StatusBar1.SimpleText := FileName; {...and open it} hFile := CreateFile(PChar(FileName),GENERIC_READ or GENERIC_WRITE,
FILE_SHARE_READ or FILE_SHARE_WRITE, @Security,
OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); {if there was an error, show a message}
if hFile = INVALID_HANDLE_VALUE then
begin
ShowMessage('Error Opening File');
Exit;
end;
end; {retrieve the last modification time} GetFileTime(hFile, nil, nil, @WriteTime); {convert the time to local file time}
FileTimeToLocalFileTime(WriteTime, LocalTime); {finally, convert the time to the system time, so that it
will match the file time displayed in the Explorer}
FileTimeToSystemTime(LocalTime, SystemTime); {convert the file time into Dos date and time components...}
FileTimeToDosDateTime(LocalTime, DosDate, DosTime); {...and convert it back} if not DosDateTimeToFileTime(DosDate, DosTime, LocalTime) then
ShowMessage ('An error occured when converting Dos date and time back to'+
' file time.'); {break out the component parts of the Dos date and time for easy display}
infoDosTime := ConvertDosTimeToSystemTime(DosTime);
infoDosDate := ConvertDosDateToSystemDate(DosDate); with infoDosTime do
Edit1.Text := ComboBox1.Items[infoDosDate.Month - 1]+ ' ' + IntToStr(infoDosDate.Day) + ',' +
IntToStr(infoDosDate.Year) + ' ' +
IntToStr(Hour) + ':' +
IntToStr(Minutes) + ':' +
IntToStr(Seconds) ; {indicate the time of day}
case SystemTime.WHour of
12 : Label1.Caption := 'PM';
13..24 : begin
Label1.Caption := 'PM';
SystemTime.wHour:=SystemTime.wHour - 12; end;
0 : SystemTime.wHour:= 12;
else
Label1.Caption := 'AM';
end; {display the last modification time of the file}
SpinEdit1.Value := SystemTime.wYear;
SpinEdit2.Value := SystemTime.wHour;
SpinEdit3.Value := SystemTime.wMinute;
SpinEdit4.Value := SystemTime.wSecond;
ComboBox1.ItemIndex := SystemTime.wMonth - 1;
Calendar1.Month := SystemTime.wMonth;
Calendar1.Day := SystemTime.wDay;end;procedure TForm1.SpeedButton3Click(Sender: TObject);
var
FileTime, LocalFileTime: TFileTime; // holds file times
SystemTime: TSystemTime; // holds system time information
begin
{prepare the time information from the values set by the user}
SystemTime.wHour := SpinEdit2.Value; if (Label1.Caption = 'PM') and (SystemTime.wHour < 12) then
SystemTime.wHour := SystemTime.wHour + 12; SystemTime.wMinute := SpinEdit3.Value;
SystemTime.wSecond := SpinEdit4.Value;
SystemTime.wYear := SpinEdit1.Value;
SystemTime.wMonth := ComboBox1.ItemIndex + 1;
SystemTime.wDay := Calendar1.Day; {convert the system time to a local file time}
SystemTimeToFileTime(SystemTime,LocalFileTime); {convert the local file time to a file time that the file system understands}
LocalFileTimeToFileTime(LocalFileTime,FileTime); {use this time to set the last modification time which shows
up in the Explorer}
SetFileTime(hFile, nil, nil, @FileTime);
end;
{ 获取文件时间,Tf表示目标文件路径和名称 }
const
Model='yyyy/mm/dd,hh:mm:ss'; { 设定时间格式 }
var
Tp:TSearchRec; { 申明Tp为一个查找记录 }
T1,T2,T3:string;begin
FindFirst(Tf,faAnyFile,Tp); { 查找目标文件 } T1:=FormatDateTime(Model,
CovFileDate(Tp.FindData.ftCreationTime)));
{ 返回文件的创建时间 }
T2:=FormatDateTime(Model,
CovFileDate(Tp.FindData.ftLastWriteTime)));
{ 返回文件的修改时间 }
T3:=FormatDateTime(Model,Now));
{ 返回文件的当前访问时间 }
FindClose(Tp);
end;