基于python的每日固定时间执行实例解析
2022/5/2 20:13:11
本文主要是介绍基于python的每日固定时间执行实例解析,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
一 概念 datetime模块属性如下所示:![](/upload/202205/02/202205022013117167.png)
import datetime import threading def func(): print("start rec audio") timer = threading.Timer(86400,func) timer.start() 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 #get next day 3:00 time #next_time = datetime.datetime.strptime(str(next_year)+"-"+str(next_month)+"-"+str(next_day)+"3:00:00"+"%Y-%m-%d %H:%M:%S") next_time = datetime.datetime.strptime(str(next_year)+"-"+str(next_month)+"-"+str(next_day)+" 03:00:00", "%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) timer.start()
三 总结 这个是对datetime的运用全面范例,值得深究。 四 参考文档 1.python 指定时间运行代码_学术菜鸟小晨的博客-CSDN博客_python指定时间运行
这篇关于基于python的每日固定时间执行实例解析的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python