比较日期以检查旧文件 [英] Comparing dates to check for old files
本文介绍了比较日期以检查旧文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查文件是否早于一定时间(例如2天)。
I want to check if a file is older than a certain amount of time (e.g. 2 days).
我设法以这样的方式获得文件创建时间方式:
I managed to get the file creation time in such a way:
>>> import os.path, time
>>> fileCreation = os.path.getctime(filePath)
>>> time.ctime(os.path.getctime(filePath))
'Mon Aug 22 14:20:38 2011'
现在如何检查是否已超过2天?
How can I now check if this is older than 2 days?
我在Linux下工作,但跨平台解决方案会更好。干杯!
I work under Linux, but a cross platform solution would be better. Cheers!
推荐答案
now = time.time()
twodays_ago = now - 60*60*24*2 # Number of seconds in two days
if fileCreation < twodays_ago:
print "File is more than two days old"
这篇关于比较日期以检查旧文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文