如何在Python中获取文件的修改日期/时间?

Mat*_*att 21 python file

如何在Python中获取文件的修改日期/时间?

Tho*_*ers 39

os.path.getmtime(filepath)
Run Code Online (Sandbox Code Playgroud)

要么

os.stat(filepath).st_mtime
Run Code Online (Sandbox Code Playgroud)


Din*_*ngo 19

格式化:

import time
print time.strftime("%m/%d/%Y %I:%M:%S %p",time.localtime(os.path.getmtime(fname)))
Run Code Online (Sandbox Code Playgroud)