16 Star 44 Fork 45

现任明教教主-乾颐堂 / qytang_Python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
2016.02.22 计算文件创建到现在的时间 778 Bytes
一键复制 编辑 原始数据 按行查看 历史
#!/usr/bin/python3
# -*- coding=utf-8 -*-
import os
import time
import datetime
def file_stay_time(filename):
CreatedTime=time.localtime(os.stat(filename).st_ctime)
y=time.strftime('%Y', CreatedTime)
m=time.strftime('%m', CreatedTime)
d=time.strftime('%d', CreatedTime)
H=time.strftime('%H', CreatedTime)
M=time.strftime('%M', CreatedTime)
ctime = datetime.datetime(int(y),int(m),int(d),int(H),int(M))
# print(ctime)
now = datetime.datetime.now()
# print(now)
seconds_to_passed = (now-ctime).seconds
mins_to_passed = seconds_to_passed/60
hours_to_passed = mins_to_passed/60
return hours_to_passed
if __name__ == "__main__":
test = file_stay_time('/python/cgi-bin/bakconfig/BJRack02_ve_xxx_2016_2_21_13.txt')
print(test)
Python
1
https://gitee.com/qytang/qytang_Python.git
git@gitee.com:qytang/qytang_Python.git
qytang
qytang_Python
qytang_Python
master

搜索帮助