Fork me on GitHub

一 概念:
python中库很多,这里熟悉下time和interval的用法
二 实例解析
切记这里的interval,输出的是目前的时间是一个数组。
import time
from interval import Interval

def do_some():
    print("some is running")

while True:
    now_localtime = time.strftime("%H:%M:%S",time.localtime())

    now_time = Interval(now_localtime,now_localtime)
    print("now_time:",now_time)

    time_interval = Interval("15:28:00","15:45:00")
    print("time_interval:",time_interval)

    if now_time in time_interval:
        print("time is in ")
        do_some()
        break

输出结果:

now_time: '15:40:32'
time_interval: ['15:28:00'..'15:45:00']
time is in 
some is running
三 总结
 
特定时间范围做特定的事情,这个比较符合的。

posted on 2022-05-02 15:44  虚生  阅读(135)  评论(0编辑  收藏  举报