c# - 在 C# 中计算 Cron 下一次运行时间

标签 c# algorithm crontab

我有类似 crontab 的调度程序。时间定义“MM HH WD MD M”:

MM-分钟
HH-小时
WD-星期几
MD-一个月中的几天
M-月

WD, MD, M 允许多个条目,每个参数可以为空,例如:

^ ^  0, 1  ^ ^      means exucution every minute, every hour, at sunday and mondey, every day<br>

35 15 ^ ^ ^    execution every day at 15.35<br>

问题是如果知道上次执行日期,如何计算下一次运行时间。我知道如何使用循环执行此操作(只需添加 1 分钟直到它符合条件),但必须有更好的方法。

最佳答案

我已经成功使用了NCrontab正是为了这个目的。

使用类似的东西

var schedule = CrontabSchedule.Parse("15 35 * * *");
return schedule.GetNextOccurrence(DateTime.Now);

关于c# - 在 C# 中计算 Cron 下一次运行时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8121374/

相关文章:

shell - 使用 shell 脚本的 Cron 作业

c# - DataTable 和 ASP.NET Repeater

c# - 错误请求仅在远程计算机上通过 IE 11 返回用于传递凭据的 XHR

python - 在 Python 中实现快速排序

c++ - 找到具有 3 个变量的丢番图方程的一个特定解和解的数量的有效算法

linux - cron 的替代品?

c# - LINQ project() 在 LINQ IQueryable 中自动从数据实体映射到业务实体?

c# - 为什么 VisualTreeHelper.GetChildrenCount 返回 0 个顶级控件?

algorithm - 按到端节点的距离对图进行排序

没有 crontab -e 的 crontab