python應(yīng)用操作——每天0點(diǎn)定時(shí)啟動(dòng)
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()
點(diǎn)擊加載更多評論>>