Python 日期和时间
python初步学习-import和datetime模块
python 每天在指定【时间段】运行程序及关闭程序
python每天固定时间运行某程序代码
Python time strftime()方法
Python time localtime()方法
还有定时的schedule模块:
import schedule
import time
#引入schedule和time
def job():
print("I'm working...")
#定义一个叫job的函数,函数的功能是打印'I'm working...'
schedule.every(10).minutes.do(job) #部署每10分钟执行一次job()函数的任务
schedule.every().hour.do(job) #部署每×小时执行一次job()函数的任务
schedule.every().day.at("10:30").do(job) #部署在每天的10:30执行job()函数的任务
schedule.every().monday.do(job) #部署每个星期一执行job()函数的任务
schedule.every().wednesday.at("13:15").do(job)#部署每周三的13:15执行函数的任务
while True:
schedule.run_pending()
time.sleep(1)
#13-15都是检查部署的情况,如果任务准备就绪,就开始执行任务。