减时间问题 [英] Subtracting Time Problem
本文介绍了减时间问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图弄清楚如何从这个时间减去20秒以及放置位置.我正在删除20秒或更短的文件.谢谢你.表示感谢!
I''m trying to figure out how to subtract 20 seconds from this time, as well as the placement. I am deleteing files that are 20 seconds or less. Thank you. Help is apprecitiated!
using namespace std;
typedef vector tFoundFilesVector;
std::wstring LastWriteTime;
//int getFileList(wstring filespec, tFoundFilesVector &foundFiles) //uni
int getFileList(const char * filespec, tFoundFilesVector &foundFiles) //ansi
{
WIN32_FIND_DATA findData;
HANDLE h;
int validResult=true;
int numFoundFiles = 0;
//h = FindFirstFile(filespec.c_str(), &findData); //uni
h = FindFirstFile((LPCSTR)filespec, &findData); //ansi
if (h == INVALID_HANDLE_VALUE)
return 0;
while (validResult)
{
numFoundFiles++;
foundFiles.push_back(findData);
validResult = FindNextFile(h, &findData);
}
return numFoundFiles;
}
void showFileAge(tFoundFilesVector &fileList)
{
unsigned _int64 fileTime, curTime, age;
tFoundFilesVector::iterator iter;
FILETIME ftNow;
CoFileTimeNow(&ftNow);
curTime = ((_int64) ftNow.dwHighDateTime << 32) + ftNow.dwLowDateTime;
for (iter=fileList.begin(); iterftLastWriteTime.dwHighDateTime << 32) + iter->ftLastWriteTime.dwLowDateTime;
age = curTime - fileTime;
if (age <= (_int64)age/10000000UL-20)
{
remove("*.*");
}
else
{
return;
}
wcout << "FILE: '" << iter->cFileName << "', AGE: " << (_int64)age/10000000UL << " seconds" << endl;
}
}
int main()
{
string fileSpec = "*.*";
tFoundFilesVector foundFiles;
tFoundFilesVector::iterator iter;
int foundCount = 0;
getFileList("c:\\Mapper\\*.txt", foundFiles);
getFileList("c:\\Mapper\\*.jpg", foundFiles);
foundCount = foundFiles.size();
if (foundCount)
{
wcout << "Found "<</pre>
推荐答案
通常我使用此功能,
In general I use this function,
char *DateDiffer(char *Date, int DayToSub)
{
struct tm time,*tmt;
time_t mtime;
int year,month,date;
char *buffer;
buffer=(char *)malloc(sizeof(char)*10);
if(Date!=NULL)
{
sscanf(Date,"%d-%d-%d",&year,&month,&date);
}
memset((char*)(&time),0,sizeof(struct tm));
time.tm_year=year-1900;
time.tm_mon=month-1;
time.tm_mday=date-DayToSub;
mtime=mktime(&time);
tmt=localtime(&mtime);
sprintf(buffer,"%04d-%02d-%02d\n",(tmt->tm_year+1900),(tmt->tm_mon+1),tmt->tm_mday);
return buffer;
}
这篇关于减时间问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文