位置:首頁 > 軟件操作教程 > 編程開發(fā) > Python > 問題詳情

python應(yīng)用操作——每天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ù)查找其他問題的答案?

相關(guān)視頻回答
回復(0)
返回頂部