import datetime import threading def set_time(func, args, time): now_time = datetime.datetime.now() # 获取明天时间 next_time = now_time + datetime.timedelta(days=+1) next_year = next_time.date().year next_month = next_time.date().month next_day = next_time.date().day # 获取明天七点的时间 next_time = datetime.datetime.strptime(str(next_year) + "-" + str(next_month) + "-" + str(next_day) + time, "%Y-%m-%d %H:%M:%S") timer_start_time = (next_time - now_time).total_seconds() print(timer_start_time) timer = threading.Timer(timer_start_time, func, args) timer.start()