无事, 直接上代码
#include <windows.h>
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
FILETIME fTm;
SYSTEMTIME sysTm;
HANDLE hFile;
hFile = CreateFile("d:/test.txt", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, NULL);
if(INVALID_HANDLE_VALUE == hFile)
{
cout << "no" <<endl;
}
GetLocalTime(&sysTm);
sysTm.wYear = 2013;
SystemTimeToFileTime(&sysTm, &fTm);
BOOL bRet = SetFileTime(hFile, &fTm, &fTm, &fTm);
int ret = GetLastError();
if(bRet)
{
cout << "ok" <<endl;
}
return 0;
}
主要调用SystemTimeToFileTime