# 字符串转日期
initDate = datetime.datetime.strptime('2021-11-03 16:44:08', '%Y-%m-%d %H:%M:%S')
# 获取当前日期
current_time =datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# 获取当前日期的小时
# datetime可以用datetime.datetime.now()方法,使用该方法可以得到该方法的year、month、day、hour、minute、second
current_hour=datetime.datetime.now().hour
# 判断当前小时是否在此范围内
if current_hour >10 and current_hour <12:
print("True")
其他时间相关的信息
Python获取当前日期、日期差计算、判断时间是否在某个时间范围内_Acheng1011的博客-CSDN博客_python判断日期在某时间区间