查找24小时之间是否经过了日期-Python我有以下方法:# last_updated is a datetime() object, representing the last time this program randef time_diff(last_updated):
day_period = last_updated.replace(day=last_updated.day+1, hour=1,
minute=0, second=0,
microsecond=0)
delta_time = day_period - last_updated
hours = delta_time.seconds // 3600
# make sure a period of 24hrs have passed before shuffling
if hours >= 24:
print "hello"
else:
print "do nothing"我想知道从那以后24小时是否已经过去了last_updated,我怎么能在Python?
2 回答
慕尼黑8549860
TA贡献1818条经验 获得超11个赞
time
datetime
if (now - then) > DAY:
datetime.timedelta
int
.
from datetime import datetime then = datetime_object now = datetime.now()if (now - then).total_seconds() > NUMBER_OF_SECONDS: # do something
添加回答
举报
0/150
提交
取消