我试图让 Python 检查给定的时间是否在未来至少 10 分钟。输入数据时,我总是返回“else”子句;The scheduled time must be at least 10 minutes from now
这是到目前为止我正在使用的代码:
while len(schedTime) == 0:
schedTime = raw_input('Scheduled Time (hh:mm): ')
schedHr = schedTime.split(':')[0]
schedMi = schedTime.split(':')[1]
try:
testTime = int(schedHr)
testTime = int(schedMi)
except:
print 'The scheduled time must be in the format hh:mm)'
schedTime = ''
continue
if int(self.hr) <= int(schedHr) and int(self.mi) + 10 <= int(schedMi):
pass
else:
print 'The scheduled time must be at least 10 minutes from now'
schedTime = ''
脚本的第二部分再往下一点(很多):
### Get the current time
now = datetime.datetime.now()
yrF = now.strftime('%Y')
moF = now.strftime('%m')
dyF = now.strftime('%d')
then = now + datetime.timedelta(minutes=10)
self.hr = then.strftime('%H')
self.mi = then.strftime('%M')