python 判断当前时间是否在某两个时间点之间

pylist 1143

python 判断当前时间是否在两个时间点之间

import datetime
import time
timestamp = datetime.datetime.now().time() # Throw away the date information
time.sleep(1)
print (datetime.datetime.now().time() > timestamp) # >>> True (unless you ran this one second before midnight!)

# Or check if a time is between two other times
start = datetime.time(8, 30)
end = datetime.time(15)
print (start <= timestamp <= end) # >>> depends on what time it is

start = datetime.time(17, 30)
end = datetime.time(18, 40)
print (datetime.datetime.now().time() > timestamp)

>>> datetime.datetime.fromtimestamp(1490345439).strftime("%Y-%m-%d %H:%M:%S.%f")
'2017-03-24 16:50:39.000000'
>>> 

登录发表评论