由于昨天临时需求,需要再接口返回时,加上工作日的判断,这里的工作日是周一到周六(9:00-18:00)
话不多说,上代码
import time
from datetime import datetime
current_date = datetime.today()
current_day_num = current_date.isoweekday()
print('当前日期', current_date)
print('当前周几', current_day_num)
上面获取到当前是周几,下面进行工作日判断
now_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print('当前时间', now_time)
#这里我只判断时分秒
now_time_hour = now_time[11:]
print('当前时分秒', now_time_hour)
if now_time_hour > '09:00:00' and now_time_hour < '18:00:00' and current_day_num != 7:
print('True')
else:
print('False')