注:
1、datetime.timedelta支持days、seconds、microseconds
2、找出24小时内的数据
3、找出超过1天、1月、1年的数据
4、配合datetime.datetime.fromtimestamp(os.path.getmtime(os.path.join(root,f)))抓取文件修改日期进行日期比较
#!/usr/bin/python
import datetime
now = datetime.datetime.now()
deltaH = datetime.timedelta(seconds=1)
deltaD = datetime.timedelta(days=1)
deltaM = datetime.timedelta(days=30)
deltaY = datetime.timedelta(days=365)
Hour = now - deltaH
day = now - deltaD
Mon = now - deltaM
Year = now - deltaY
print Hour
print day
print Mon
print Year
:wq
原文地址:http://blog.51cto.com/yangzhiming/2127930