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

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

PHP中文网
PHP中文网

认证高级PHP讲师

répondre à tous(2)
黄舟

在Linux中,没有文件创建时间的概念。只有文件的访问时间、修改时间、状态改变时间。也就是说不能知道文件的创建时间。

但如果文件创建后就没有修改过,修改时间=创建时间;如果文件创建后,状态就没有改变过,那么状态改变时间=创建时间;如果文件创建后,没有被读取过,那么访问时间=创建时间,这个基本不太可能。

与文件相关的几个时间:

  1. 访问时间,读一次这个文件的内容,这个时间就会更新。比如对这个文件使用more命令。ls、stat命令都不会修改文件的访问时间。

  2. 修改时间,对文件内容修改一次,这个时间就会更新。比如:vi后保存文件。ls -l列出的时间就是这个时间。

  3. 状态改变时间。通过chmod命令更改一次文件属性,这个时间就会更新。

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.

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!