Python获得文件时间戳

http://zhidao.baidu.com/link?url=wNI9K20mR7-9necxd6zK1bWnBQ-EmuggOzS0JNVZ0G_mpsqN31tI6l3I0j0dyYcAnHuXoQLS6axyv0cB0Yx3cG9dncoIv5N4QEgW7hAfQXi

我们通过文件属性的获取,os.stat() 方法:

>>> import os
>>> statinfo=os.stat(r"C:/1.txt")
>>> statinfo
(33206, 0L, 0, 0, 0, 0, 29L, 1201865413, 1201867904, 1201865413)
使用os.stat的返回值statinfo的三个属性获取文件的创建时间等
st_atime (访问时间), st_mtime (修改时间), st_ctime(创建时间),例如,取得文件修改时间:
>>> statinfo.st_mtime
1201865413.8952832
这个时间是一个linux时间戳,需要转换一下
使用time模块中的localtime函数可以知道:
>>> import time
>>> time.localtime(statinfo.st_ctime)
(2008, 2, 1, 19, 30, 13, 4, 32, 0)
2008年2月1日的19时30分13秒(2008-2-1 19:30:13)



原文地址:https://www.cnblogs.com/qiangupc/p/4177102.html