转载本站文章请注明,转载自: 月影鹏鹏 [http://Jacky.Aiwaly.com]
本文链接: http://jk.aiwaly.com/wp/python%e8%8e%b7%e5%be%97%e5%b9%b6%e8%be%93%e5%87%ba%e6%96%87%e4%bb%b6%e5%b1%9e%e6%80%a7.html
import os
import time
file = “samples/sample.jpg”
def dump(st):
mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime = st
print “- size:”, size, “bytes”
print “- owner:”, uid, gid
print “- created:”, time.ctime(ctime)
print “- last accessed:”, time.ctime(atime)
print “- last modified:”, time.ctime(mtime)
print “- mode:”, oct(mode)
print “- inode/dev:”, ino, dev
# get stats for a filename
st = os.stat(file)
print “station”, file
dump(st)
print st
# get stats for an open file
fp = open(file)
st = os.fstat(fp.fileno())
print “fstat”, file
dump(st)
print st.st_ctime
201865413.8952832
import os
>>> o=os.stat(r’F:\\Xunlei\160103.doc’)
>>> t=o.st_ctime
>>> t
1202624180.046875
>>> print type(t)
>>> import time
>>> r=time.ctime(t)
>>> r
‘Sun Feb 10 14:16:20 2008′
>>> s=time.gmtime(t)
>>> s
(2008, 2, 10, 6, 16, 20, 6, 41, 0)
>>> time.strftime(“%a, %d %b %Y %H:%M:%S +0000″, s)
‘Sun, 10 Feb 2008 06:16:20 +0000′
>>> import time
>>> time.localtime(statinfo.st_ctime)
(2008, 2, 1, 19, 30, 13, 4, 32, 0)