1 Star 0 Fork 46

xiaozhu1215/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)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/xiaozhu1215/qytang_Python.git
git@gitee.com:xiaozhu1215/qytang_Python.git
xiaozhu1215
qytang_Python
qytang_Python
master

搜索帮助