取得修改时间的函数FileTimeToSystemTime怎么用

WYJBCB 2004-01-17 09:51:31
里面有两参数,但我不知道怎么用,能不能举一个例子.
...全文
1368 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
Chimae 2004-02-01
  • 打赏
  • 举报
回复
TDateTime __fastcall TfrmContract::GetFileTime(String tmpFile, int intType)
{
//获取文件修改日期;
WIN32_FIND_DATA ffd;
WORD fd, ft;
DWORD fdt;
FILETIME lft, Time;
HANDLE H;
//搜索文件得到文件句柄;
H = FindFirstFile(tmpFile.c_str(), &ffd);
//察看日期类型;
switch (intType)
{
case 0:
Time = ffd.ftCreationTime;//创建时间;
break;
case 1:
Time = ffd.ftLastWriteTime;//最后修改时间;
break;
case 2:
Time = ffd.ftLastAccessTime;//最后访问时间;
break;
default:
Time = ffd.ftCreationTime;
}
//获取文件信息;
if (H!=INVALID_HANDLE_VALUE)
{
//只找到一个文件,关掉文件;
FindClose(H);
//转换FILETIME格式为LOCAL FILETIME格式;
FileTimeToLocalFileTime(&Time, &lft);
//转换FILETIME格式成为DOSTIME格式;
FileTimeToDosDateTime(&lft, &fd, &ft);
//最后转换成TDATETIME格式输出;
return FileDateToDateTime(MAKELONG(ft, fd));
}
else
return TDateTime();//默认当前时间;
}
sun_wyz 2004-02-01
  • 打赏
  • 举报
回复
up
WYJBCB 2004-02-01
  • 打赏
  • 举报
回复
To 楼上的:我已经调用了你的代码,但它怎么没反映啊?GetLastWriteTime是返回一个Bool,但我如何让它显示出时间?谢谢
神医CL 2004-01-31
  • 打赏
  • 举报
回复
int nHandle;
char czTemp[100];
nHandle = FileOpen("c:\\1.txt",fmOpenRead);
if (nHandle == -1) return;
GetLastWriteTime((HANDLE)nHandle,(LPSTR)czTemp);
FileClose(nHandle);
WYJBCB 2004-01-30
  • 打赏
  • 举报
回复
自已顶一下,HANDLE hFile, LPSTR lpszString这两个变量怎么用?能不能举个例子调用一下 esiedull(无之趣) 兄给的函数?

heng2003 2004-01-28
  • 打赏
  • 举报
回复
bool ExtractFileTime(char* FileName,TDateTime& CreateTime,TDateTime& AccessTime,TDateTime& WriteTime)
{
if(!FileName || FileName[0]=='\0'){
return false;
}
HANDLE hfile = CreateFile(FileName,GENERIC_READ,0,0,OPEN_EXISTING,0,0);
//这里是用CreateFile 或许一个文件的句柄,里面的参数你得找帮助或是资料看看
if(hfile!=INVALID_HANDLE_VALUE){
FILETIME ftcreate,ftwrite,ftaccess;
if(GetFileTime(hfile,&ftcreate,&ftaccess,&ftwrite)){
SYSTEMTIME stcreate,stwrite,staccess;

FileTimeToLocalFileTime(&ftcreate,&ftcreate);
FileTimeToLocalFileTime(&ftaccess,&ftaccess);
FileTimeToLocalFileTime(&ftwrite,&ftwrite);

FileTimeToSystemTime(&ftcreate,&stcreate);
FileTimeToSystemTime(&ftaccess,&staccess);
FileTimeToSystemTime(&ftwrite,&stwrite);

CreateTime = SystemTimeToDateTime(stcreate);
AccessTime = SystemTimeToDateTime(staccess);
WriteTime = SystemTimeToDateTime(stwrite);

CloseHandle(hfile);

return true;
}else{
CloseHandle(hfile);
return false;
}
}else{
return false;
}
}

这段函数是得到一个文件的创建时间,最后修改和访问时间
WYJBCB 2004-01-26
  • 打赏
  • 举报
回复
自已顶一下,HANDLE hFile, LPSTR lpszString这两个变量怎么用?能不能举个例子调用一下 esiedull(无之趣) 兄给的函数?
WYJBCB 2004-01-21
  • 打赏
  • 举报
回复
自已顶一下
WYJBCB 2004-01-18
  • 打赏
  • 举报
回复
HANDLE hFile, LPSTR lpszString这两个变量怎么用?
esiedull 2004-01-17
  • 打赏
  • 举报
回复
给你段例子
BOOL GetLastWriteTime(HANDLE hFile, LPSTR lpszString)
{
FILETIME ftCreate, ftAccess, ftWrite;
SYSTEMTIME stUTC, stLocal;

// Retrieve the file times for the file.
if (!GetFileTime(hFile, &ftCreate, &ftAccess, &ftWrite))
return FALSE;

// Convert the last-write time to local time.
FileTimeToSystemTime(&ftWrite, &stUTC);
SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);

// Build a string showing the date and time.
wsprintf(lpszString, "%02d/%02d/%d %02d:%02d",
stLocal.wDay, stLocal.wMonth, stLocal.wYear,
stLocal.wHour, stLocal.wMinute);

return TRUE;
}
esiedull 2004-01-17
  • 打赏
  • 举报
回复
The FileTimeToSystemTime function converts a file time to system time format.


BOOL FileTimeToSystemTime(
const FILETIME* lpFileTime,
LPSYSTEMTIME lpSystemTime
);

Parameters
lpFileTime
[in] Pointer to a FILETIME structure containing the file time to convert to system date and time format.
This value must be less than 0x8000000000000000. Otherwise, the function fails.

lpSystemTime
[out] Pointer to a SYSTEMTIME structure to receive the converted file time.
Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

13,871

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧