最近,在数据分析中,需要判断当前时间是否为工作时间:9:00:18:00
[En]
Recently, in the data analysis, it is necessary to judge whether the current time is the working time: 9: 00: 00: 18: 00
二、代码实现
import datetime
# 范围时间
d_time = datetime.datetime.strptime(str(datetime.datetime.now().date()) + '9:00', '%Y-%m-%d%H:%M')
d_time1 = datetime.datetime.strptime(str(datetime.datetime.now().date()) + '18:00', '%Y-%m-%d%H:%M')
# 当前时间
n_time = datetime.datetime.now()
# 判断当前时间是否在范围时间内
if n_time > d_time and n_time < d_time1:
print(True)
else:
print(False)
高管产出:真
[En]
Executive output: True
Original: https://www.cnblogs.com/insane-Mr-Li/p/15378957.html
Author: tooltime
Title: python 判断当前时间是否在一个时间范围内
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/6203/
转载文章受原作者版权保护。转载请注明原作者出处!