Python方法获取得文件创建日期不正确是为什么?,python创建日期,python 版本是 2


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

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

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

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

与文件相关的几个时间:

编橙之家文章,

评论关闭