c/c++获取和修改windows下文件修改时间
程序员文章站
2022-05-24 14:37:09
...
string GetModifyTime(const char* pstrFilename)
{
struct _stat64i32 statbuf;
_tstat(pstrFilename, &statbuf);
tm tmCurTime;
_localtime64_s(&tmCurTime, &(statbuf.st_mtime));
char szRet[MAX_PATH];
_stprintf(szRet, "%4d-%02d-%02d %02d:%02d:%02d", tmCurTime.tm_year+1900, tmCurTime.tm_mon+1, tmCurTime.tm_mday, tmCurTime.tm_hour, tmCurTime.tm_min, tmCurTime.tm_sec);
return string(szRet);
}
void SetModifyTime(const char* pstrFilename, const char* pstrTime)
{
if(pstrTime == NULL)
return;
struct tm tmCurTime;
sscanf(pstrTime, "%4d-%02d-%02d %02d:%02d:%02d", &tmCurTime.tm_year, &tmCurTime.tm_mon, &tmCurTime.tm_mday, &tmCurTime.tm_hour, &tmCurTime.tm_min, &tmCurTime.tm_sec);
tmCurTime.tm_year -= 1900;
tmCurTime.tm_mon -= 1;
time_t rawtime = mktime(&tmCurTime);
_utimbuf mvTime;
mvTime.actime = rawtime;
mvTime.modtime = rawtime;
_utime(pstrFilename, &mvTime);
}
参考:https://blog.csdn.net/gongxie0235/article/details/105244906
上一篇: java文件修改时间排序
下一篇: ServletContext上下文
推荐阅读