无论哪种编程语言,时间肯定都是非常重要的部分,今天来看一下python如何来处理时间和python定时任务,注意咯:本篇所讲是python3版本的实现,在python2版本中的实现略有不同,有时间会再写一篇以便大家区分。
1.计算明天和昨天的日期
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
2.计算上一个的时间
方法一:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
方法二:借助模运算寻找上一个星期五
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
3.计算歌曲的总播放时间
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
4.反复执行某个命令
1 2 3 4 5 6 7 8 9 10 11 12 |
|
5.定时任务
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
6.利用sched实现周期调用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|