Home  >  Q&A  >  body text

python 取得文件创建日期不正确?

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

PHP中文网PHP中文网2714 days ago692

reply all(2)I'll reply

  • 黄舟

    黄舟2017-04-17 13:10:55

    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.

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 13:10:55

    你不是 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.

    reply
    0
  • Cancelreply