如何在Python中获取文件的修改日期/时间?
答
os.path.getmtime(filepath)
或
os.stat(filepath).st_mtime
答
格式化:
import time
print time.strftime("%m/%d/%Y %I:%M:%S %p",time.localtime(os.path.getmtime(fname)))
哪个更好? :) – endolith 2012-03-01 15:14:50
@endolith:http://stackoverflow.com/a/237082/125507说: “os.path.getmtime()针对本作中,更简单。” – endolith 2012-03-01 15:19:08