我需要找出在 Linux 中使用 C++ 创建文件的时间和日期。
如何获取文件的最后修改日期? http://www.jb.man.ac.uk/~slowe/cpp/lastmod.html.
struct stat attrib; //1. create a file attribute structure
stat("file_name", &attrib); //2. get the attributes of afile.txt
clock = gmtime(&(attrib.st_mtime)); //3. Get the last modified time and
// put it into the time structure
4.8 文件时间更新 http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html:
在 Linux 中:与文件关联的三个不同的时间戳:
- 上次访问内容的时间(
atime
),
- 最后一次修改内容的时间(
mtime
),
- 以及最后一次修改 inode 的时间(元数据,
ctime
).
所以,不,你cannot查找文件创建时间。(参考) https://unix.stackexchange.com/questions/24441/get-file-created-creation-time。一些与您的问题相关的有用链接:
-
如何执行 ls 然后按创建日期对结果进行排序? https://unix.stackexchange.com/questions/20460/how-do-i-do-a-ls-and-then-sort-the-results-by-date-created
-
获取文件创建/创建时间? https://unix.stackexchange.com/questions/24441/get-file-created-creation-time
- 一篇好文章,“文件创建时间” http://lwn.net/Articles/397442/.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)