linux 获取本地文件最后修改时间 c++

time是指从1970年1月一日到本地时刻的秒数

#include <iostream>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

using namespace std;


int main()
{
    struct stat buf;
    FILE *pFile;
    pFile = fopen("/centos/zheng.txt", "r");
    int fd = fileno(pFile);
    fstat(fd, &buf);
    long time = buf.st_mtime;
    cout << time << endl;
    fclose(pFile);
}

猜你喜欢

转载自blog.csdn.net/mp295345033/article/details/50144475