python應用操作——每天0點定時啟動
提問人:ylm發(fā)布時間:2020-09-29
from threading import Timerimport datetime
def fun():
print('Zarten')
timer = Timer(24*60*60, fun)
timer.start()
now = datetime.datetime.now()
tomorrow_time = now + datetime.timedelta(1)tomorrow_year = tomorrow_time.yeartomorrow_month = tomorrow_time.monthtomorrow_day = tomorrow_time.day
tomorrow_zero_time = datetime.datetime.strptime(str(tomorrow_year)+"-"+str(tomorrow_month)+"-"+str(tomorrow_day)+" 00:00:00", "%Y-%m-%d %H:%M:%S")
interval_time = (tomorrow_zero_time - now).total_seconds()
timer = Timer(interval_time, fun)timer.start()
繼續(xù)查找其他問題的答案?
相關視頻回答
點擊加載更多評論>>