這似乎可能是一個家庭作業問題。這是足夠的示例代碼,讓你開始?這可能不是最有效的,但它會起作用。
from datetime import datetime, time, timedelta
now = datetime.now()
today = datetime.date(now)
tomorrow = today + timedelta(days=1)
time_a = time (4, 0)
today_a = datetime.combine(today, time_a)
tomorrow_a = datetime.combine(tomorrow, time_a)
if (today_a - now)>timedelta(0):
print "%s is in the future" % today_a
if (tomorrow_a - now)>timedelta(0):
print "%s is in the future" % tomorrow_a
有關的時間, 「T」 的列表,可以使用: T = [時間(5,30),時間(8,30),時間(13,0),時間(17, 30)] 現在= datetime.now()
today = [x for x in t if datetime.combine(today, x) > now]
not_today = set(t) - set(today)
我從未見過的'[T [(J + I)%LEN(T)]在範圍Ĵ(LEN(t))的]'的東西,但它是在'包'或'技巧。 – Phil
太棒了。這次真是萬分感謝。 –