-1
我必須查找格式爲datetime.datetime.now().replace(microsecond=0)
的某個時間段是否大於5分鐘。我怎樣才能做到這一點?這是我的代碼:使用Python中的日期時間模塊比較時間
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"
可能重複[如何找到兩個日期時間對象在Python中的時間差?](http://stackoverflow.com/questions/1345827/how-do-i-find-the-time-兩個日期時間對象在python中的差異) – fredtantini
但這不是在兩個日期時間對象之間! –
@AlokNaushad,不,它恰好是兩個日期時間對象。 – Dmitry