python 计算 crontab 下次

代码语言:javascript
复制
python3.6 -m pip install croniter
代码语言:javascript
复制
import croniter

import datetime

def run_get_next_time(sched):
now = datetime.datetime.now()
cron = croniter.croniter(sched, now)
return [cron.get_next(datetime.datetime).strftime("%Y-%m-%d %H:%M")][0]

print(run_get_next_time("* * * * *"))