我目前正在嘗試弄清楚如何使用Pendulum在凌晨 1 點到早上 7 點 (01:00-07:00) 之間進行持續時間——我一直在嘗試閱讀檔案,但我能找到的最接近的東西是duration使用我看不到如何檢查時間是否在 01:00 到 07:00 之間。
我想知道是否可以使用鐘擺來檢查時間是否在間隔之間?
預計:
列印出“The time is between 01:00 to 07:00”,如果不是則列印“The time is NOT between 01:00 to 07:00”
uj5u.com熱心網友回復:
如果我對你的理解是正確的,你正在尋找確定給定時間是否在 01:00 和 07:00 之間。老實說,你可以只使用datetime而不是安裝一個新包。使用datetime,我會這樣做:
import datetime
curr_time = datetime.datetime.now() # replace this line with whatever time or how you get your time
if curr_time.hour >= 1 and curr_time.hour < 7:
print("The time is between 01:00 to 07:00")
else:
print("The time is NOT between 01:00 and 07:00")
由于無論如何pendulum繼承自datetime,如果您真的想使用pendulum. 您只需要更改一些語法。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/537296.html
