c++ - 如何比较两个时间时间戳
问题描述
我需要比较文件修改时间和当前本地时间的两次时间戳。
更改文件时间戳后,我想通过持续监控运行以下语句 = while 循环
我尝试使用 ctime 转换将文件的 time_t 值和当前本地时间转换为字符串,但是如何比较两个 ctime 值?而且我还尝试将 ctime 字符串存储到 char* 并尝试比较以下字符串但没有结果
struct stat attr;
stat(path, &attr);
ctime(&attr.st_mtime) /* modified time of a file in a string format */
time_t timev;
time(&timev);
ctime(&timev) ;
if (ctime(&timev) != ctime(&attr.st_mtime) ){
printf("enter code here statements");
}
else{
printf("enter code here statements");
}
char* string;
char* buffertime1 ;
string = ctime(&attr.st_mtime) ;
buffertime1 = ctime(&timev) ;
if (string !=buffertime1 ){
printf(enter code here statements);
}
else{
printf(enter code here statements);
}
int result = strcmp(buffertime1, buffertime);
if (result == 0){
std::cout << "Both Strings are equal" << std::endl;
}
else{
std::cout << "Both Strings are not equal";
}
解决方案
推荐阅读
- javascript - JQGrid - 在没有本地数据的情况下管理分页和列过滤(loadonce = false)
- javascript - 在 Laravel 中实现可嵌入的自定义徽章
- javascript - 如何在本机反应中记录每次更新的动画值?
- django - 如何在 django 布尔字段上应用条件?
- redirect - 将子域页面重定向到主域页面
- angular - Angular 模板驱动的表单不显示默认值
- css - 在 ReactJS 中使用 Bootstrap 创建块按钮
- html - 我无法将表单放在屏幕右侧:(
- reactjs - 是否可以使用 react-easy-crop 裁剪多个图像?
- python - 用什么代替 DO_NOTHING 只删除一个字段?