datetime.datetime.now().replace(microsecond=0)
형식의 특정 기간이 5 분보다 큰지 찾아야합니다. 어떻게해야합니까? 당신은 difference = timedelta(minutes=5)
을 사용할 수 있습니다Python에서 datetime 모듈을 사용하여 시간 비교
ttime = datetime.now().replace(microsecond=0)
print "Current Time:- "+str(ttime)
a = raw_input("Press y and Enter")
if a=="y":
print "OK!"
ntime = datetime.now().replace(microsecond=0)
difference = ntime-ttime
if difference> #I don't know what to put!:
print "Difference is greater than 5 min"
else:
print "Difference is not greater than 5 min"
가능한 복제 [I 파이썬에서 두 날짜 객체 사이의 시간 차이를 어떻게 찾을 수 있습니까?] (http://stackoverflow.com/questions/1345827/how-do-i-find-the-time- 차이점 - 두 - datetime-objects-in-python) – fredtantini
그러나 이것은 두 datetime 객체 사이에 있지 않습니다! –
@AlokNaushad, 아니요, 정확하게 두 datetime 개체입니다. – Dmitry