python 取得文件创建日期不正确?
PHP中文网
PHP中文网 2017-04-17 13:08:55
0
2
734

python 版本是 2.7
使用 os.path.getctime(file) 取得的文件创建日期和文件的真实的创建日期不一致。我的文件是18日创建的,可是取得的i日期却是26日?请问这是为什么?如何取得正确的日期?谢谢

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(2)
黄舟

In Linux, there is no concept of file creation time. Only the access time, modification time, and status change time of the file. In other words, the creation time of the file cannot be known.

But if the file has not been modified since it was created, the modification time = creation time; if the status has not changed since the file was created, then the status change time = creation time; if the file has not been read since it was created, then Access time = creation time, this is basically impossible.

A few times related to the file:

  1. Access time, read the content of this file once, and this time will be updated. For example, use the more command on this file. Neither the ls nor the stat commands will modify the access time of the file.

  2. Modification time, if the file content is modified once, the time will be updated. For example: save the file after vi. The time listed by ls -l is this time.

  3. Status change time. If you change the file attributes once through the chmod command, the time will be updated.

Peter_Zhu

你不是 windows 吧
os.path.getctime(path)
Return the system’s ctime which, on some systems (like Unix) is the time of the last metadata change, and, on others (like Windows), is the creation time for path. The return value is a number giving the number of seconds since the epoch (see the time module). Raise os.error if the file does not exist or is inaccessible.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template