我要用到API函数FileTimeToSystemTime(),请问怎么实现。
解决方案 »
- 向工作线程中传递this指针
- 绘图代码 error C2061: 语法错误 求解.
- 为啥俺的AcitveX控件是dll的?
- 关于用ofstream写文件的问题,请朋友们帮忙
- VC能用比double更高的精度吗
- 如果我想从C#转到C++上来,会有多大困难,还有vc .Net 和vc6.0有多大差别?
- 用WINEXEC调用一个可执行文件,如何判断执行完毕 (在线等 当日结贴)
- 谁能详细讲解一下,当刚开机的时候,系统都向网络上发送哪些包?
- 在对话框中将菜单项ENABLE/DISABLE问题!
- 关于InstallShield7.0的问题?请高手帮忙!
- CTabView简单问题,拿分走人!
- [win32 sdk及mfc]关于转化的一个问题。
__in const FILETIME* lpFileTime,
__out LPSYSTEMTIME lpSystemTime
);使用时引入Windows.h就行了。
::FileTimeToSystemTime
直接调用就可以了
// MSDN例子
#include <windows.h>
#include <tchar.h>
#include <strsafe.h>// GetLastWriteTime - Retrieves the last-write time and converts
// the time to a string
//
// Return value - TRUE if successful, FALSE otherwise
// hFile - Valid file handle
// lpszString - Pointer to buffer to receive stringBOOL GetLastWriteTime(HANDLE hFile, LPTSTR lpszString, DWORD dwSize)
{
FILETIME ftCreate, ftAccess, ftWrite;
SYSTEMTIME stUTC, stLocal;
DWORD dwRet; // 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.
dwRet = StringCchPrintf(lpszString, dwSize,
TEXT("%02d/%02d/%d %02d:%02d"),
stLocal.wMonth, stLocal.wDay, stLocal.wYear,
stLocal.wHour, stLocal.wMinute); if( S_OK == dwRet )
return TRUE;
else return FALSE;
}int _tmain(int argc, TCHAR *argv[])
{
HANDLE hFile;
TCHAR szBuf[MAX_PATH]; if( argc != 2 )
{
printf("This sample takes a file name as a parameter\n");
return 0;
}
hFile = CreateFile(argv[1], GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, 0, NULL); if(hFile == INVALID_HANDLE_VALUE)
{
printf("CreateFile failed with %d\n", GetLastError());
return 0;
}
if(GetLastWriteTime( hFile, szBuf, MAX_PATH ))
_tprintf(TEXT("Last write time is: %s\n"), szBuf); CloseHandle(hFile);
}