我有时差
time1 = datetime.datetime.fromtimestamp(time.mktime(time.gmtime()))
...
time2 = datetime.datetime.fromtimestamp(time.mktime(time.gmtime()))
diff = time2 - time1
Run Code Online (Sandbox Code Playgroud)
现在,我如何找到通过的总秒数?diff.seconds不计算天数.我可以:
diff.seconds + diff.days * 24 * 3600
Run Code Online (Sandbox Code Playgroud)
有没有内置的方法?
我有以下方法:
# last_updated is a datetime() object, representing the last time this program ran
def 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"
Run Code Online (Sandbox Code Playgroud)
我想知道从那以后24小时过去了last_updated,我怎么能这样做last_updated呢?