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

Posted

技术标签:

【中文标题】如何在 Python 中获取文件的修改日期/时间? [复制]【英文标题】:How do I get the modified date/time of a file in Python? [duplicate] 【发布时间】:2010-09-12 08:53:55 【问题描述】:

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

【问题讨论】:

【参考方案1】:
os.path.getmtime(filepath)

os.stat(filepath).st_mtime

【讨论】:

@endolith: ***.com/a/237082/125507 说“os.path.getmtime() 就是为此而生的,而且更简单。”【参考方案2】:

格式化:

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

【讨论】:

以上是关于如何在 Python 中获取文件的修改日期/时间? [复制]的主要内容,如果未能解决你的问题,请参考以下文章