import datetime now = datetime.datetime.now() print('当前时间:', now) print('小时:', now.hour) if now.hour < 16: yesterday = now - datetime.timedelta(days=1) check_date = yesterday.strftime('%Y%m%d') print('检查日期:', check_date) else: check_date = now.strftime('%Y%m%d') print('检查日期:', check_date)