python 判断当前时间是否在两个时间点之间
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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)
1
2
3
>>> datetime.datetime.fromtimestamp(1490345439).strftime("%Y-%m-%d %H:%M:%S.%f")
'2017-03-24 16:50:39.000000'
>>>
本文网址: https://pylist.com/topic/143.html 转摘请注明来源